Class: Howard::ArrivalsResource
- Inherits:
-
Object
- Object
- Howard::ArrivalsResource
- Includes:
- Enumerable
- Defined in:
- lib/howard/arrivals_resource.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #arrivals_params(params) ⇒ Object
- #each ⇒ Object
- #gateway ⇒ Object
-
#initialize(params = {}) ⇒ ArrivalsResource
constructor
A new instance of ArrivalsResource.
- #xml_response ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ ArrivalsResource
Returns a new instance of ArrivalsResource.
7 8 9 |
# File 'lib/howard/arrivals_resource.rb', line 7 def initialize(params={}) @params = arrivals_params(params) end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/howard/arrivals_resource.rb', line 5 def params @params end |
Instance Method Details
#arrivals_params(params) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/howard/arrivals_resource.rb', line 27 def arrivals_params(params) { mapid: params[:mapid] || params[:station], stpid: params[:stpid] || params[:stop], max: params[:max], rt: params[:rt] || params[:route], }.reject { |_, val| val.nil? } end |
#each ⇒ Object
11 12 13 14 15 |
# File 'lib/howard/arrivals_resource.rb', line 11 def each Array(xml_response["ctatt"]["eta"]) .map { |eta| Arrival.new(eta) } .each { |arrival| yield arrival } end |
#gateway ⇒ Object
17 18 19 |
# File 'lib/howard/arrivals_resource.rb', line 17 def gateway @gateway ||= TrainTrackerGateway.new(Howard.train_tracker_api_key) end |
#xml_response ⇒ Object
21 22 23 24 25 |
# File 'lib/howard/arrivals_resource.rb', line 21 def xml_response @xml_resonse ||= gateway .arrivals(query: params) .parsed_response end |