Class: EasyTransilien::Station

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_transilien/station.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_timeObject

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_codeObject

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_areaObject

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

#nameObject

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(options = {})
  options[:force] ||= false
  if options[: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:

Parameters:

  • criterium (String) (defaults to: nil)

    will try to match name or external_code. Both case unsensitive.



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

#codesObject



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

#linesObject



54
55
56
# File 'lib/easy_transilien/station.rb', line 54

def lines
  @lines ||= EasyTransilien::Line.find()
end