Class: SimlarWord
- Inherits:
-
Object
- Object
- SimlarWord
- Defined in:
- lib/timex_datalink_caldav/similar_word.rb
Defined Under Namespace
Classes: WordNotFound
Instance Attribute Summary collapse
-
#database ⇒ Object
Returns the value of attribute database.
Instance Method Summary collapse
-
#initialize(database:) ⇒ SimlarWord
constructor
A new instance of SimlarWord.
- #vocab_ids_for(*words) ⇒ Object
Constructor Details
#initialize(database:) ⇒ SimlarWord
Returns a new instance of SimlarWord.
12 13 14 |
# File 'lib/timex_datalink_caldav/similar_word.rb', line 12 def initialize(database:) @database = database end |
Instance Attribute Details
#database ⇒ Object
Returns the value of attribute database.
10 11 12 |
# File 'lib/timex_datalink_caldav/similar_word.rb', line 10 def database @database end |
Instance Method Details
#vocab_ids_for(*words) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/timex_datalink_caldav/similar_word.rb', line 16 def vocab_ids_for(*words) words.flat_map do |word| vocab = vocab_for_word(word) # If the word is not found, look for a similar sounding word if vocab.nil? word = find_similar_word(word) vocab = vocab_for_word(word) end raise(WordNotFound, "#{word} is not a valid word!") unless vocab vocab_links = vocab_links_for_vocab(vocab) vocab_links.map do |vocab_link| linked_vocab = vocab_for_vocab_link(vocab_link) linked_vocab[:"PC Index"].to_i end end end |