Class: OEIS::OEISParser
- Inherits:
-
Object
- Object
- OEIS::OEISParser
- Defined in:
- lib/oeis.rb
Overview
Your code goes here…
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) ⇒ OEISParser
constructor
A new instance of OEISParser.
- #to_s ⇒ Object
Constructor Details
#initialize(ls) ⇒ OEISParser
Returns a new instance of OEISParser.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/oeis.rb', line 13 def initialize(ls) url = BASE_URL + ls.join(',') begin doc = Nokogiri::HTML(open(url)) rescue SocketError puts 'Connection could not be established. Check your internet connection.' end first_result = doc.css('table table:eq(2)').first info = first_result.css('tr:eq(3) table > tr > td > a').first if info.nil? puts 'No sequence found.' return nil end @id = info.attributes['href'].value[1..-1] @title = info.attributes['title'].value 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.
11 12 13 |
# File 'lib/oeis.rb', line 11 def id @id end |
#sequence ⇒ Object
Returns the value of attribute sequence.
11 12 13 |
# File 'lib/oeis.rb', line 11 def sequence @sequence end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/oeis.rb', line 11 def title @title end |
Instance Method Details
#to_s ⇒ Object
36 37 38 |
# File 'lib/oeis.rb', line 36 def to_s "#{@id}: #{@title}" end |