Class: WiktionaryAPI::Word
- Inherits:
-
Object
- Object
- WiktionaryAPI::Word
- Defined in:
- lib/wiktionary_api/word.rb
Instance Attribute Summary collapse
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#part_of_speech ⇒ Object
readonly
Returns the value of attribute part_of_speech.
-
#raw_definitions ⇒ Object
readonly
Returns the value of attribute raw_definitions.
Instance Method Summary collapse
- #definitions ⇒ Object
- #examples ⇒ Object
-
#initialize(data) ⇒ Word
constructor
A new instance of Word.
Constructor Details
#initialize(data) ⇒ Word
Returns a new instance of Word.
5 6 7 8 9 |
# File 'lib/wiktionary_api/word.rb', line 5 def initialize(data) @part_of_speech = data['partOfSpeech'] @language = data['language'] @raw_definitions = data['definitions'] end |
Instance Attribute Details
#language ⇒ Object (readonly)
Returns the value of attribute language.
3 4 5 |
# File 'lib/wiktionary_api/word.rb', line 3 def language @language end |
#part_of_speech ⇒ Object (readonly)
Returns the value of attribute part_of_speech.
3 4 5 |
# File 'lib/wiktionary_api/word.rb', line 3 def part_of_speech @part_of_speech end |
#raw_definitions ⇒ Object (readonly)
Returns the value of attribute raw_definitions.
3 4 5 |
# File 'lib/wiktionary_api/word.rb', line 3 def raw_definitions @raw_definitions end |
Instance Method Details
#definitions ⇒ Object
11 12 13 |
# File 'lib/wiktionary_api/word.rb', line 11 def definitions @raw_definitions.flat_map { |meaning| ::Nokogiri::HTML(meaning['definition']).text.strip } end |
#examples ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/wiktionary_api/word.rb', line 15 def examples @raw_definitions.flat_map do |definition| definition["examples"].map do |e| ::Nokogiri::HTML(e).text.strip end end.compact end |