Class: Metlinkr::Trip
- Inherits:
-
Object
- Object
- Metlinkr::Trip
- Defined in:
- lib/metlinkr/trip.rb
Instance Attribute Summary collapse
-
#steps ⇒ Object
Returns the value of attribute steps.
Class Method Summary collapse
Instance Attribute Details
#steps ⇒ Object
Returns the value of attribute steps.
4 5 6 |
# File 'lib/metlinkr/trip.rb', line 4 def steps @steps end |
Class Method Details
.parse(html) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/metlinkr/trip.rb', line 6 def self.parse(html) trip = new doc = Nokogiri::HTML(html) rows = doc.xpath("//table[@text-align='top']/tr") rows = rows.to_a.reject do |row| # Reject the hidden ones klass = row.attributes['class'].value rescue "" klass =~ /addinfo|jpText/ end rows.shift # Get rid of header row if rows.length % 3 != 0 raise "Rows not a multiple of 3" end trip.steps = [] rows.each_slice(3) do |row_set| trip.steps << Step.parse(row_set) end trip end |