Class: TokyoMetro::Test::Api::TrainTimetable::TrainInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/tokyo_metro/test/api/train_timetable/train_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(train) ⇒ TrainInfo

Returns a new instance of TrainInfo.



3
4
5
6
7
8
9
10
# File 'lib/tokyo_metro/test/api/train_timetable/train_info.rb', line 3

def initialize( train )
  @train_number = train.train_number
  @railway_direction = train.railway_direction
  @starting_station = train.starting_station
  @terminal_station = train.terminal_station
  @first_station_of_station_time_infos = train.valid_array.first.station
  @last_station_of_station_time_infos = train.valid_array.last.station
end

Instance Attribute Details

#first_station_of_station_time_infosObject (readonly)

Returns the value of attribute first_station_of_station_time_infos.



12
13
14
# File 'lib/tokyo_metro/test/api/train_timetable/train_info.rb', line 12

def first_station_of_station_time_infos
  @first_station_of_station_time_infos
end

#last_station_of_station_time_infosObject (readonly)

Returns the value of attribute last_station_of_station_time_infos.



12
13
14
# File 'lib/tokyo_metro/test/api/train_timetable/train_info.rb', line 12

def last_station_of_station_time_infos
  @last_station_of_station_time_infos
end

#railway_directionObject (readonly)

Returns the value of attribute railway_direction.



12
13
14
# File 'lib/tokyo_metro/test/api/train_timetable/train_info.rb', line 12

def railway_direction
  @railway_direction
end

#starting_stationObject (readonly)

Returns the value of attribute starting_station.



12
13
14
# File 'lib/tokyo_metro/test/api/train_timetable/train_info.rb', line 12

def starting_station
  @starting_station
end

#terminal_stationObject (readonly)

Returns the value of attribute terminal_station.



12
13
14
# File 'lib/tokyo_metro/test/api/train_timetable/train_info.rb', line 12

def terminal_station
  @terminal_station
end

#train_numberObject (readonly)

Returns the value of attribute train_number.



12
13
14
# File 'lib/tokyo_metro/test/api/train_timetable/train_info.rb', line 12

def train_number
  @train_number
end

Instance Method Details

#<=>(other) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/tokyo_metro/test/api/train_timetable/train_info.rb', line 14

def <=>( other )
  array_of_methods = [ :railway_direction , :starting_station , :terminal_station , :first_station_of_station_time_infos , :last_station_of_station_time_infos ]
  evaluated_string = array_of_methods.map { | method_name |
    "compare_sub( #{method_name} , other )"
  }.join( " do ; " ) + " ; end" * ( array_of_methods.length - 1 )

  eval( evaluated_string )
end

#outputObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/tokyo_metro/test/api/train_timetable/train_info.rb', line 39

def output
  arr = [
    [ "Starting station" , station_name_in_db( @starting_station ) ] ,
    [ "First station of station time infos" , station_name_in_db( @first_station_of_station_time_infos ) ] ,
    [ "Last station of station time infos" , station_name_in_db( @last_station_of_station_time_infos ) ] ,
    [ "Terminal station" , station_name_in_db( @terminal_station ) ] ,
    [ "Railway direction" , @railway_direction ]
  ]
=begin
  arr.each_with_index.map { | element , i |
    title , var = element
    str = title.ljust(48) + " : " + var
    if i == 0
      "○ #{str}"
    else
      " " * 3 + str
    end
  }.join( "\n" )
=end
  arr.map { | element | element.join( ":" ) }.join( "\n" )
end

#to_aObject



23
24
25
# File 'lib/tokyo_metro/test/api/train_timetable/train_info.rb', line 23

def to_a
  [ @train_number ] + to_a_without_train_number
end

#to_a_without_train_numberObject



31
32
33
# File 'lib/tokyo_metro/test/api/train_timetable/train_info.rb', line 31

def to_a_without_train_number
  [ @railway_direction , @starting_station , @terminal_station , @first_station_of_station_time_infos , @last_station_of_station_time_infos ]
end

#to_sObject



27
28
29
# File 'lib/tokyo_metro/test/api/train_timetable/train_info.rb', line 27

def to_s
  to_a.join( "\n" )
end

#to_s_without_train_numberObject



35
36
37
# File 'lib/tokyo_metro/test/api/train_timetable/train_info.rb', line 35

def to_s_without_train_number
  to_a_without_train_number.join( "\n" )
end