Class: OEIS::Parser
- Inherits:
-
Object
- Object
- OEIS::Parser
- Defined in:
- lib/oeis.rb
Constant Summary collapse
- BASE_URL =
'http://oeis.org/search?q='
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(ls) ⇒ Parser
constructor
A new instance of Parser.
- #to_s ⇒ Object
Constructor Details
#initialize(ls) ⇒ Parser
Returns a new instance of Parser.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/oeis.rb', line 12 def initialize(ls) url = BASE_URL + ls.join(',') doc = Nokogiri::HTML(open(url)) first_result = doc.css('table table:eq(2)').first info = first_result.css('tr:eq(3) table > tr').first if info.nil? puts 'No sequence found.' return nil end @id = info.css('td:eq(1) > a').text.strip @title = info.css('td:eq(3)').text.strip digits = first_result.css('tr:eq(4) table tr tt').text.split(', ') @sequence = digits.map &:to_i end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/oeis.rb', line 10 def id @id end |
#sequence ⇒ Object
Returns the value of attribute sequence.
10 11 12 |
# File 'lib/oeis.rb', line 10 def sequence @sequence end |
#title ⇒ Object
Returns the value of attribute title.
10 11 12 |
# File 'lib/oeis.rb', line 10 def title @title end |
Instance Method Details
#to_s ⇒ Object
31 32 33 |
# File 'lib/oeis.rb', line 31 def to_s "#{@id}: #{@title}" end |