Class: Metanym
- Inherits:
-
Object
- Object
- Metanym
- Defined in:
- lib/metanym.rb
Constant Summary collapse
- VERSION =
"0.1.0"
- URL =
"http://thesaurus.com/browse/"
Instance Method Summary collapse
- #antonyms ⇒ Object
- #definition ⇒ Object
- #doc ⇒ Object
-
#initialize(query) ⇒ Metanym
constructor
A new instance of Metanym.
- #items_at(head) ⇒ Object
- #source ⇒ Object
- #synonyms ⇒ Object
Constructor Details
Instance Method Details
#antonyms ⇒ Object
18 19 20 |
# File 'lib/metanym.rb', line 18 def antonyms @antonyms ||= items_at 'Antonyms' end |
#definition ⇒ Object
22 23 24 25 26 |
# File 'lib/metanym.rb', line 22 def definition @definition ||= doc.at_xpath('//td[.="Definition:"]/following::td').text rescue NoMethodError nil end |
#doc ⇒ Object
34 35 36 |
# File 'lib/metanym.rb', line 34 def doc @doc ||= Nokogiri.HTML source end |
#items_at(head) ⇒ Object
28 29 30 31 32 |
# File 'lib/metanym.rb', line 28 def items_at(head) doc.at_xpath("//td[.='#{head}:']/following-sibling::td").text.strip.split(/[\n,]\s*/) rescue NoMethodError [] end |
#source ⇒ Object
38 39 40 |
# File 'lib/metanym.rb', line 38 def source Excon.get(@url, :expects => 200).body end |
#synonyms ⇒ Object
14 15 16 |
# File 'lib/metanym.rb', line 14 def synonyms @synonyms ||= items_at 'Synonyms' end |