Class: Bort::Realtime::Estimates
- Inherits:
-
Object
- Object
- Bort::Realtime::Estimates
- Defined in:
- lib/bort/realtime.rb
Constant Summary collapse
- VALID_PLATFORMS =
%w(1 2 3 4)
- VALID_DIRECTIONS =
%w(n s)
Instance Attribute Summary collapse
-
#destinations ⇒ Object
Returns the value of attribute destinations.
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#fetched_at ⇒ Object
Returns the value of attribute fetched_at.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#trains ⇒ Object
Returns the value of attribute trains.
Instance Method Summary collapse
-
#initialize(orig, options = {}) ⇒ Estimates
constructor
A new instance of Estimates.
- #select(type, value = nil) ⇒ Object (also: #filter)
Constructor Details
#initialize(orig, options = {}) ⇒ Estimates
Returns a new instance of Estimates.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bort/realtime.rb', line 8 def initialize(orig, ={}) self.origin = orig () = { :action => 'etd', :cmd => 'etd', :orig => origin, :plat => platform, :dir => direction, } xml = Util.download() data = Hpricot(xml) self.origin = (data/:abbr).inner_text self.fetched_at = Time.parse((data/:time).inner_text) self.trains = [] self.destinations = [] (data/:etd).map do |estimate| destination = (estimate/:abbreviation).inner_text self.destinations << destination (estimate/:estimate).map do |train| self.trains << Train.new(train, origin, destination) end end end |
Instance Attribute Details
#destinations ⇒ Object
Returns the value of attribute destinations.
4 5 6 |
# File 'lib/bort/realtime.rb', line 4 def destinations @destinations end |
#direction ⇒ Object
Returns the value of attribute direction.
4 5 6 |
# File 'lib/bort/realtime.rb', line 4 def direction @direction end |
#fetched_at ⇒ Object
Returns the value of attribute fetched_at.
4 5 6 |
# File 'lib/bort/realtime.rb', line 4 def fetched_at @fetched_at end |
#origin ⇒ Object
Returns the value of attribute origin.
4 5 6 |
# File 'lib/bort/realtime.rb', line 4 def origin @origin end |
#platform ⇒ Object
Returns the value of attribute platform.
4 5 6 |
# File 'lib/bort/realtime.rb', line 4 def platform @platform end |
#trains ⇒ Object
Returns the value of attribute trains.
4 5 6 |
# File 'lib/bort/realtime.rb', line 4 def trains @trains end |
Instance Method Details
#select(type, value = nil) ⇒ Object Also known as: filter
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bort/realtime.rb', line 37 def select(type, value=nil) filters = if type.class == Hash type else { type => value } end trains.select do |train| filters.all? do |type, value| train.send(type) == value end end end |