Class: Whatsa::Disambig
- Inherits:
-
Object
- Object
- Whatsa::Disambig
- Defined in:
- lib/whatsa/disambig.rb
Instance Attribute Summary collapse
-
#descriptions ⇒ Object
Returns the value of attribute descriptions.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #choices ⇒ Object
- #choose_article(choice) ⇒ Object
-
#initialize(noko_doc) ⇒ Disambig
constructor
A new instance of Disambig.
Constructor Details
#initialize(noko_doc) ⇒ Disambig
Returns a new instance of Disambig.
5 6 7 8 9 |
# File 'lib/whatsa/disambig.rb', line 5 def initialize(noko_doc) @title = noko_doc.css('h1').text @items = noko_doc.css('#mw-content-text li') @descriptions = make_descriptions end |
Instance Attribute Details
#descriptions ⇒ Object
Returns the value of attribute descriptions.
2 3 4 |
# File 'lib/whatsa/disambig.rb', line 2 def descriptions @descriptions end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
3 4 5 |
# File 'lib/whatsa/disambig.rb', line 3 def items @items end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/whatsa/disambig.rb', line 3 def title @title end |
Instance Method Details
#choices ⇒ Object
11 12 13 |
# File 'lib/whatsa/disambig.rb', line 11 def choices self.descriptions.keys end |
#choose_article(choice) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/whatsa/disambig.rb', line 15 def choose_article(choice) if choice.to_i > 0 Whatsa::Scraper.new(choices[choice.to_i - 1]).make_article else Whatsa::Scraper.new(choice).make_article end end |