Class: TokyoMetro::Api::StationTimetable::Info::TrainTime::List
- Inherits:
-
MetaClass::Fundamental::List
- Object
- Array
- MetaClass::Fundamental::List
- TokyoMetro::Api::StationTimetable::Info::TrainTime::List
- Defined in:
- lib/tokyo_metro/api/station_timetable/info/train_time/list.rb
Overview
個別の列車の情報の配列
時刻表の情報の取得 collapse
-
#to_strf(indent = 0) ⇒ String
インスタンスの情報を整形した文字列にして返すメソッド.
列車の出発時刻に関するメソッド collapse
-
#after_now(d = ::TokyoMetro.time_now) ⇒ List <Info>
(also: #will_arrive)
指定された時刻より後に出発する列車を取得するメソッド.
-
#before_now(d = ::TokyoMetro.time_now) ⇒ List <Info>
(also: #already_depart)
指定された時刻より前に出発する列車を取得するメソッド.
列車の行先に関するメソッド collapse
-
#bound_for(*stations) ⇒ ::Array <Train>
特定の行先の列車を取得するメソッド.
列車の停車駅に関するメソッド collapse
-
#first_train_after_now(d = Time.now, number: 1, bound_for: nil, stop_at: nil) ⇒ List <Train>
指定された時刻より後に出発し、特定の駅に停車する/特定の駅を行先とする最初の n 本の列車を取得するメソッド.
-
#last_train_depart_after_the_day_change? ⇒ Boolean
日付が変わった後に終電があるか否かの判定.
-
#last_train_not_departed_yet?(d = ::TokyoMetro.time_now) ⇒ Boolean
終電の出発前か否かの判定.
-
#stop_at(*stations) ⇒ List <Train>
(also: #go_to)
特定の駅に停車する列車を取得するメソッド.
Class Method Summary collapse
Instance Method Summary collapse
- #seed(*args) ⇒ Object
-
#terminal_stations ⇒ Object
# @note TrainTimetable::Info::StationTime::List#seed と同じロジック def seed( id_in_db , operation_day_id , railway_line_in_db , station_info_in_db ) raise “Error: #selfself.classself.class.name##__method__” self.each do | train | train.seed( id_in_db , operation_day_id , railway_line_in_db , station_info_in_db ) end end.
Methods inherited from MetaClass::Fundamental::List
Class Method Details
.factory_for_seeding_this_class ⇒ Object
11 12 13 |
# File 'lib/tokyo_metro/api/station_timetable/info/train_time/list.rb', line 11 def self.factory_for_seeding_this_class factory_for_seeding_train_times_in_each_station end |
Instance Method Details
#after_now(d = ::TokyoMetro.time_now) ⇒ List <Info> Also known as: will_arrive
指定された時刻より後に出発する列車を取得するメソッド
57 58 59 |
# File 'lib/tokyo_metro/api/station_timetable/info/train_time/list.rb', line 57 def after_now( d = ::TokyoMetro.time_now ) self.class.new( self.select { | train | train.after_now?(d) } ) end |
#before_now(d = ::TokyoMetro.time_now) ⇒ List <Info> Also known as: already_depart
指定された時刻より前に出発する列車を取得するメソッド
50 51 52 |
# File 'lib/tokyo_metro/api/station_timetable/info/train_time/list.rb', line 50 def before_now( d = ::TokyoMetro.time_now ) self.class.new( self.select { | train | train.before_now?(d) } ) end |
#bound_for(*stations) ⇒ ::Array <Train>
行先を複数指定した場合は、指定された【いずれか】の駅を行先とする列車を取得する。
特定の行先の列車を取得するメソッド
67 68 69 |
# File 'lib/tokyo_metro/api/station_timetable/info/train_time/list.rb', line 67 def bound_for( *stations ) self.class.new( self.select { | train | train.bound_for?( *stations ) } ) end |
#first_train_after_now(d = Time.now, number: 1, bound_for: nil, stop_at: nil) ⇒ List <Train>
指定された時刻より後に出発し、特定の駅に停車する/特定の駅を行先とする最初の n 本の列車を取得するメソッド
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/tokyo_metro/api/station_timetable/info/train_time/list.rb', line 84 def first_train_after_now( d = Time.now , number: 1 , bound_for: nil , stop_at: nil ) i = 0 ary = ::Array.new self.each do | train | if train.departure_time >= d and train.bound_for?( *bound_for ) and train.stops_at?( *stop_at ) if number == 1 return train else ary << train i += 1 end end if i = number break end end self.new( ary ) end |
#last_train_depart_after_the_day_change? ⇒ Boolean
配列の最後の列車が 0:00 - 2:59 の間に出発するか否かによって判定を行う。
日付が変わった後に終電があるか否かの判定
110 111 112 |
# File 'lib/tokyo_metro/api/station_timetable/info/train_time/list.rb', line 110 def last_train_depart_after_the_day_change? self.last.departure_datetime.hour < ::TokyoMetro::DATE_CHANGING_HOUR end |
#last_train_not_departed_yet?(d = ::TokyoMetro.time_now) ⇒ Boolean
配列の最後の列車が出発前か否かによって判定を行う。
終電の出発前か否かの判定
118 119 120 |
# File 'lib/tokyo_metro/api/station_timetable/info/train_time/list.rb', line 118 def last_train_not_departed_yet?( d = ::TokyoMetro.time_now ) d <= self.last.departure_datetime( today: false ) end |
#seed(*args) ⇒ Object
7 8 9 |
# File 'lib/tokyo_metro/api/station_timetable/info/train_time/list.rb', line 7 def seed( *args ) super( *args , indent: 2 , not_on_the_top_layer: true , interrupt: false ) end |
#stop_at(*stations) ⇒ List <Train> Also known as: go_to
停車駅を複数指定した場合は、指定された【すべて】の駅に停車する列車を取得する。
特定の駅に停車する列車を取得するメソッド
78 79 80 |
# File 'lib/tokyo_metro/api/station_timetable/info/train_time/list.rb', line 78 def stop_at( *stations ) self.class.new( self.select { | train | train.stops_at?( *stations ) } ) end |
#terminal_stations ⇒ Object
# @note TrainTimetable::Info::StationTime::List#seed と同じロジック
def seed( id_in_db , operation_day_id , railway_line_in_db , station_info_in_db )
raise "Error: #{self.class.name}\##{__method__}"
self.each do | train |
train.seed( id_in_db , operation_day_id , railway_line_in_db , station_info_in_db )
end
end
# @note 各列車の時刻の処理
def seed( , operation_day_in_db , )
self.each do | train |
train.seed( , operation_day_in_db , )
end
end
32 33 34 |
# File 'lib/tokyo_metro/api/station_timetable/info/train_time/list.rb', line 32 def terminal_stations self.map( &:terminal_station ).uniq.sort end |
#to_strf(indent = 0) ⇒ String
インスタンスの情報を整形した文字列にして返すメソッド
41 42 43 |
# File 'lib/tokyo_metro/api/station_timetable/info/train_time/list.rb', line 41 def to_strf( indent = 0 ) super( indent , 1 ) end |