Class: EasyTransilien::Station
- Inherits:
-
Object
- Object
- EasyTransilien::Station
- Defined in:
- lib/easy_transilien/station.rb
Instance Attribute Summary collapse
-
#access_time ⇒ Object
Returns the value of attribute access_time.
-
#external_code ⇒ Object
Returns the value of attribute external_code.
-
#ms_stop_area ⇒ Object
Returns the value of attribute ms_stop_area.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
-
.all_stop_areas(options = {}) ⇒ Object
Get all available ‘Transilien::StopArea` == See: `transilien_microservices` gem.
- .convert_stop_areas_to_stations(stop_areas) ⇒ Object
-
.find(criterium = nil) ⇒ Object
Find a list of ‘Station` matching
criterium
.
Instance Method Summary collapse
Instance Attribute Details
#access_time ⇒ Object
Returns the value of attribute access_time.
3 4 5 |
# File 'lib/easy_transilien/station.rb', line 3 def access_time @access_time end |
#external_code ⇒ Object
Returns the value of attribute external_code.
3 4 5 |
# File 'lib/easy_transilien/station.rb', line 3 def external_code @external_code end |
#ms_stop_area ⇒ Object
Returns the value of attribute ms_stop_area.
4 5 6 |
# File 'lib/easy_transilien/station.rb', line 4 def ms_stop_area @ms_stop_area end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/easy_transilien/station.rb', line 3 def name @name end |
Class Method Details
.all_stop_areas(options = {}) ⇒ Object
Get all available ‘Transilien::StopArea`
See:
‘transilien_microservices` gem
10 11 12 13 14 15 16 |
# File 'lib/easy_transilien/station.rb', line 10 def all_stop_areas( = {}) [:force] ||= false if [:force] || @all_stop_areas.nil? @all_stop_areas = ::Transilien::StopArea.find end @all_stop_areas end |
.convert_stop_areas_to_stations(stop_areas) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/easy_transilien/station.rb', line 41 def convert_stop_areas_to_stations(stop_areas) stop_areas.map do |sa| item = new item.name = sa.name item.external_code = sa.external_code item.access_time = sa.access_time item.ms_stop_area = sa item end end |
.find(criterium = nil) ⇒ Object
Find a list of ‘Station` matching criterium
. Valid keys:
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/easy_transilien/station.rb', line 21 def find(criterium = nil) if criterium.is_a?(String) regex = /#{criterium}/i matching = all_stop_areas.reject { |sa| sa.name !~ regex && sa.external_code !~ regex } return convert_stop_areas_to_stations(matching) elsif criterium.is_a?(Station) return [criterium] elsif criterium.is_a?(Hash) matching = [] if criterium.keys.include?(:line_external_code) all_stop_areas.select { |sa| raise sa.inspect } end return convert_stop_areas_to_stations(matching) elsif criterium.nil? return convert_stop_areas_to_stations(all_stop_areas) else raise 'WAZZUF?' end end |
Instance Method Details
#codes ⇒ Object
58 59 60 |
# File 'lib/easy_transilien/station.rb', line 58 def codes @codes ||= ms_stop_area.lines.map(&:code).flatten.uniq.sort#.reject { |c| c.length != 1 } # DEV NOTE lines with more than 1 letter are special lines for "travaux" end |
#coord(format = :gps) ⇒ Object
62 63 64 65 |
# File 'lib/easy_transilien/station.rb', line 62 def coord(format = :gps) if format == :gps end end |
#lines ⇒ Object
54 55 56 |
# File 'lib/easy_transilien/station.rb', line 54 def lines @lines ||= EasyTransilien::Line.find() end |