class TokyoMetro::Test::Api::TrainTimetable::TrainInfo
Attributes
first_station_of_station_time_infos[R]
last_station_of_station_time_infos[R]
railway_direction[R]
starting_station[R]
terminal_station[R]
train_number[R]
Public Class Methods
new( train )
click to toggle source
# 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
Public Instance Methods
<=>( other )
click to toggle source
# 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
output()
click to toggle source
# 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_a()
click to toggle source
# 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_number()
click to toggle source
# 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_s()
click to toggle source
# 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_number()
click to toggle source
# 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
Private Instance Methods
compare_sub( method_name , other ) { || ... }
click to toggle source
# File lib/tokyo_metro/test/api/train_timetable/train_info.rb, line 63 def compare_sub( method_name , other ) case self.send( method_name ) <=> other.send( method_name ) when 1 return 1 when -1 return -1 else if block_given? yield else 0 end end end
station_name_in_db( station_name_same_as )
click to toggle source
# File lib/tokyo_metro/test/api/train_timetable/train_info.rb, line 78 def station_name_in_db( station_name_same_as ) station_info_in_db = ::STATIONS.find_by_same_as( station_name_same_as ) station_info_in_db.name_ja + "(" + station_info_in_db.railway_line.name_ja_with_operator_name + ")" end