Class: CtaTrack::Stops
- Inherits:
-
Object
- Object
- CtaTrack::Stops
- Defined in:
- lib/stops.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#stops ⇒ Object
readonly
Returns the value of attribute stops.
Instance Method Summary collapse
-
#initialize(args) ⇒ Stops
constructor
A new instance of Stops.
- #keys ⇒ Object
- #method_missing(method_name, stop, *arguments, &block) ⇒ Object
- #respond_to?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(args) ⇒ Stops
Returns a new instance of Stops.
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
#result ⇒ Object (readonly)
Returns the value of attribute result.
3 4 5 |
# File 'lib/stops.rb', line 3 def result @result end |
#stops ⇒ Object (readonly)
Returns the value of attribute stops.
3 4 5 |
# File 'lib/stops.rb', line 3 def stops @stops end |
Instance Method Details
#keys ⇒ Object
18 19 20 |
# File 'lib/stops.rb', line 18 def keys @result.keys end |
#respond_to?(method_name, include_private = false) ⇒ 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 |