Class: CTA::TrainTracker
Constant Summary collapse
- @@key =
nil
Class Method Summary collapse
- .arrivals(options = {}) ⇒ Object
- .key ⇒ Object
- .key=(key) ⇒ Object
- .stations ⇒ Object
- .stop_table ⇒ Object
- .stops ⇒ Object
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(={}) .merge!({ :key => @@key }) response = get("/ttarrivals.aspx", :query => )['ctatt'] check_for_errors response results = Array.wrap response['eta'] results.map { |result| Hashie::Mash.new result } unless results.nil? end |
.key ⇒ Object
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 |
.stations ⇒ Object
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_table ⇒ Object
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 |
.stops ⇒ Object
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 |