Class: Chouette::TransportMode

Inherits:
ActiveSupport::StringInquirer
  • Object
show all
Defined in:
app/models/chouette/transport_mode.rb

Constant Summary collapse

@@definitions =
[
  ["interchange", -1],
  ["unknown", 0],
  ["coach", 1],
  ["air", 2],
  ["waterborne", 3],
  ["bus", 4],
  ["ferry", 5],
  ["walk", 6],
  ["metro", 7],
  ["shuttle", 8],
  ["rapid_transit", 9],
  ["taxi", 10],
  ["local_train", 11],
  ["train", 12],
  ["long_distance_train", 13],
  ["tramway", 14],
  ["trolleybus", 15],
  ["private_vehicle", 16],
  ["bicycle", 17],
  ["other", 18]
]
@@all =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text_code, numerical_code) ⇒ TransportMode

Returns a new instance of TransportMode.



3
4
5
6
# File 'app/models/chouette/transport_mode.rb', line 3

def initialize(text_code, numerical_code)
  super text_code.to_s
  @numerical_code = numerical_code
end

Class Method Details

.allObject



61
62
63
64
65
# File 'app/models/chouette/transport_mode.rb', line 61

def self.all
  @@all ||= definitions.collect do |text_code, numerical_code|
    new(text_code, numerical_code)
  end
end

.new(text_code, numerical_code = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/chouette/transport_mode.rb', line 8

def self.new(text_code, numerical_code = nil)
  if text_code and numerical_code
    super
  elsif self === text_code 
    text_code
  else
    if Fixnum === text_code
      text_code, numerical_code = definitions.rassoc(text_code)
    else
      text_code, numerical_code = definitions.assoc(text_code.to_s)
    end

    super text_code, numerical_code
  end
end

Instance Method Details

#inspectObject



28
29
30
# File 'app/models/chouette/transport_mode.rb', line 28

def inspect
  "#{to_s}/#{to_i}"
end

#nameObject



32
33
34
# File 'app/models/chouette/transport_mode.rb', line 32

def name
  camelize
end

#public_transport?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/chouette/transport_mode.rb', line 67

def public_transport?
  not interchange?
end

#to_iObject



24
25
26
# File 'app/models/chouette/transport_mode.rb', line 24

def to_i
  @numerical_code
end