Class: CTA::TrainTracker

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cta-api.rb

Constant Summary collapse

@@key =
nil

Class Method Summary collapse

Class Method Details

.arrivals(options = {}) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
# File 'lib/cta-api.rb', line 151

def self.arrivals(options={})
  options.merge!({
    :key => @@key
  })

  response = get("/ttarrivals.aspx", :query => options)['ctatt']
  check_for_errors response

  results = Array.wrap response['eta']
  results.map { |result| Hashie::Mash.new result } unless results.nil?
end

.keyObject



181
182
183
# File 'lib/cta-api.rb', line 181

def self.key
  @@key
end

.key=(key) ⇒ Object



185
186
187
# File 'lib/cta-api.rb', line 185

def self.key=(key)
  @@key = key
end

.stationsObject



168
169
170
171
# File 'lib/cta-api.rb', line 168

def self.stations
  stations = stop_table.map { |stop| [stop['PARENT_STOP_ID'], stop['STATION_DESCRIPTIVE_NAME']] }.flatten
  Hash[*stations]
end

.stop_tableObject



173
174
175
176
177
178
179
# File 'lib/cta-api.rb', line 173

def self.stop_table
  stop_data = []
  CSV.read(File.dirname(__FILE__) + "/cta_L_stops.csv").each_with_index do |line, index|
    index == 0 ? @headers = line : stop_data << Hash[ @headers.zip line ]
  end
  stop_data
end

.stopsObject



163
164
165
166
# File 'lib/cta-api.rb', line 163

def self.stops
  stops = stop_table.map { |stop| [stop['STOP_ID'], stop['STOP_NAME']] }.flatten
  Hash[*stops]
end