Class: EasyTransilien::Line

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

Overview

ET::Line is NOT the translation of MS::Line It’s the port of commercial names known by customers: “Ligne J”, “Ligne L”, etc. So, it’s a collection of MS::Line, with (normally) a common MS::Network

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_timeObject

Returns the value of attribute access_time.



6
7
8
# File 'lib/easy_transilien/line.rb', line 6

def access_time
  @access_time
end

#codesObject

Returns the value of attribute codes.



6
7
8
# File 'lib/easy_transilien/line.rb', line 6

def codes
  @codes
end

#ms_networkObject

Returns the value of attribute ms_network.



7
8
9
# File 'lib/easy_transilien/line.rb', line 7

def ms_network
  @ms_network
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/easy_transilien/line.rb', line 6

def name
  @name
end

Class Method Details

.all_ms_lines(options = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/easy_transilien/line.rb', line 18

def all_ms_lines(options = {})
  options[:force] ||= false
  if options[:force] || @all_ms_lines.nil?
    @all_ms_lines = ::Transilien::Line.find
  end
  @all_ms_lines
end

.all_networks(options = {}) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/easy_transilien/line.rb', line 10

def all_networks(options = {})
  options[:force] ||= false
  if options[:force] || @all_networks.nil?
    @all_networks = ::Transilien::Network.find
  end
  @all_networks
end

.convert_networks_to_lines(networks) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/easy_transilien/line.rb', line 42

def convert_networks_to_lines(networks)
  networks.map do |n|
    item = new
    item.name          = n.name
    item.access_time   = n.access_time
    item.ms_network    = n
    item.ms_lines << n.lines
    item.ms_lines.compact!
    item
  end
end

.find(criterium = nil) ⇒ Object

Find a line via a single letter (A,B,C,D,E,I,J,K,L, etc.)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/easy_transilien/line.rb', line 27

def find(criterium = nil)
  if criterium.is_a?(String)
    regexp = /#{criterium}/i
    matching = all_networks.reject { |n| n.name !~ regexp && n.external_code !~ regexp && !n.codes.map(&:downcase).include?(criterium.downcase) }
    if matching.length == 1 # Ok, seems sucessful
      return convert_networks_to_lines(matching)
    end
  elsif criterium.nil?
    # No Args? Return everything.
    return convert_networks_to_lines(all_networks)
  else
    raise "Can't understand #find criteria: not a letter, not nil, not a network line name: #{criterium.inspect}"
  end
end

Instance Method Details

#line_external_codesObject

<< self



55
56
57
58
59
60
# File 'lib/easy_transilien/line.rb', line 55

def line_external_codes
  @lines_external_codes ||= begin
    return nil unless ms_lines
    ms_lines.map(&:external_code).sort.uniq
  end
end

#ms_linesObject



66
67
68
69
70
# File 'lib/easy_transilien/line.rb', line 66

def ms_lines
  @ms_lines ||= []
  @ms_lines.flatten!
  @ms_lines
end

#stationsObject



72
73
74
# File 'lib/easy_transilien/line.rb', line 72

def stations
  @stations ||= EasyTransilien::Station.convert_stop_areas_to_stations(ms_lines.map { |ms_line| ms_line.stop_areas }.flatten.uniq)
end