Class: Bart::Etd

Inherits:
Object
  • Object
show all
Defined in:
lib/bart/etd.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Etd

Returns a new instance of Etd.



9
10
11
12
13
14
15
16
# File 'lib/bart/etd.rb', line 9

def initialize(xml)
  document  = Nokogiri::XML.parse(xml)
  abbr      = document.css('abbreviation').text
  estimates = document.css('estimate')

  @destination = Station.new(abbr: abbr)
  @estimates   = estimates.inject([]) { |memo, i| memo << Estimate.new(i.to_s) }
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



7
8
9
# File 'lib/bart/etd.rb', line 7

def destination
  @destination
end

#estimatesObject (readonly)

Returns the value of attribute estimates.



7
8
9
# File 'lib/bart/etd.rb', line 7

def estimates
  @estimates
end

Instance Method Details

#to_sObject



18
19
20
# File 'lib/bart/etd.rb', line 18

def to_s
  "#{destination.name} #{estimates.map(&:minutes) * ', '}"
end