Class: CtaTrack::Stops

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Stops

Returns a new instance of Stops.

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/stops.rb', line 4

def initialize(args)
  raise ArgumentError, "must enter api key" if API.apikey.nil? 
  @result = {}
  @stops = []
  API.stops(args).root.xpath("stop").each do |node|
    @result[node.xpath('stpid').text.to_i] = {
      :stpid => node.xpath("stpid").text.to_i,
      :stpnm => node.xpath("stpnm").text,
      :lat => node.xpath("lat").text.to_i, 
      :lon => node.xpath("lon").text.to_i
    }
    @stops << node.xpath("stpnm").text
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, stop, *arguments, &block) ⇒ Object



21
22
23
# File 'lib/stops.rb', line 21

def method_missing(method_name, stop, *arguments, &block)
  @result[stop][method_name.to_sym]
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



3
4
5
# File 'lib/stops.rb', line 3

def result
  @result
end

#stopsObject (readonly)

Returns the value of attribute stops.



3
4
5
# File 'lib/stops.rb', line 3

def stops
  @stops
end

Instance Method Details

#keysObject



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

def keys 
  @result.keys
end

#respond_to?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/stops.rb', line 24

def respond_to?(method_name, include_private=false)
  @result[@result.keys[0]].include?("#{method_name}".to_sym)
end