Class: Lunar::Words

Inherits:
Array
  • Object
show all
Defined in:
lib/lunar/words.rb

Overview

i.e. Words.new(“the quick brown”) == %w(the quick brown)

Constant Summary collapse

UnknownFilter =
Class.new(ArgumentError)
SEPARATOR =
/\s+/
FILTERS =
[:stopwords, :downcase, :uniq]

Instance Method Summary collapse

Constructor Details

#initialize(str, filters = []) ⇒ Words

Returns a new instance of Words.



12
13
14
15
16
17
18
19
20
# File 'lib/lunar/words.rb', line 12

def initialize(str, filters = [])
  words = str.split(SEPARATOR).
    reject { |w| w.to_s.strip.empty? }.
    map    { |w| sanitize(w) }

  apply_filters(words, filters)

  super(words)
end