class NytJourneys::Journeys
Attributes
description[RW]
name[RW]
type[RW]
url[RW]
Public Class Methods
all()
click to toggle source
# File lib/nyt_journeys/journeys.rb, line 15 def self.all @@all end
create_from_collection(trip_array)
click to toggle source
# File lib/nyt_journeys/journeys.rb, line 11 def self.create_from_collection(trip_array) trip_array.each {|trip| self.new(trip)} end
find(id)
click to toggle source
# File lib/nyt_journeys/journeys.rb, line 19 def self.find(id) all[id - 1] end
find_by_type(type)
click to toggle source
# File lib/nyt_journeys/journeys.rb, line 27 def self.find_by_type(type) all.select {|journey| journey.type == type} end
new(trip_hash)
click to toggle source
# File lib/nyt_journeys/journeys.rb, line 6 def initialize(trip_hash) trip_hash.each {|k,v| self.send("#{k}=",v)} @@all << self end
types()
click to toggle source
# File lib/nyt_journeys/journeys.rb, line 23 def self.types all.collect {|journey| journey.type}.uniq end
Public Instance Methods
cost()
click to toggle source
# File lib/nyt_journeys/journeys.rb, line 43 def cost cost ||= doc.css("div.price p").text[/\$\S+/] end
dates()
click to toggle source
# File lib/nyt_journeys/journeys.rb, line 51 def dates dates ||= doc.css("div.departures a.departure-link").collect {|date_range| date_range.text} end
doc()
click to toggle source
# File lib/nyt_journeys/journeys.rb, line 31 def doc Nokogiri::HTML(open(url)) end
itinerary()
click to toggle source
# File lib/nyt_journeys/journeys.rb, line 55 def itinerary itinerary ||= doc.css("div.primary-information").collect do |day| "#{day.css("div.day-number").text} - #{day.css("h3.day-title").text}" end end
length()
click to toggle source
# File lib/nyt_journeys/journeys.rb, line 47 def length length ||= doc.css("div.itinerary-info > p").text.strip[/.+s/] end