Worst_day

Some days are the worst…

def process_file(filename, limit=12)
  total_size, unique_words = nil, nil

  [File.read(filename)
  .sub(/.*<<start>>/m, "")
  .sub(/<<end>>.*/m, "")
  .gsub(/<<ignore>>.*?<<\/ignore>>/m, "")
  .scan(/\p{L}+/)
  .then { OPTS['stop-words'] ?
    (it - STOP_WORDS).reject {|w| w.size < 4 } : it }
    .tap { total_size = it.size }
  .tally.tap { unique_words = it.size }
  .sort_by { |word, count| -count }
  .first(limit), total_size, unique_words]
end