class TokyoMetro::Api::StationTimetable::Info::TrainTime::List

個別の列車の情報の配列

Public Class Methods

factory_for_seeding_this_class() click to toggle source
# 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

Public Instance Methods

after_now( d = ::TokyoMetro.time_now ) click to toggle source

指定された時刻より後に出発する列車を取得するメソッド @param d [DateTime] 時刻の設定(デフォルトは現在時刻) @return [List <Info>]

# 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
Also aliased as: will_arrive
already_depart( d = ::TokyoMetro.time_now )
Alias for: before_now
before_now( d = ::TokyoMetro.time_now ) click to toggle source

指定された時刻より前に出発する列車を取得するメソッド @param d [DateTime] 時刻の設定(デフォルトは現在時刻) @return [List <Info>]

# 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
Also aliased as: already_depart
bound_for( *stations ) click to toggle source

特定の行先の列車を取得するメソッド @param stations [::Array <Station>] 行先 @return [::Array <Train>] @note 行先を複数指定した場合は、指定された【いずれか】の駅を行先とする列車を取得する。

# 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
Also aliased as: go_to
first_train_after_now( d = Time.now , number: 1 , bound_for: nil , stop_at: nil ) click to toggle source

指定された時刻より後に出発し、特定の駅に停車する/特定の駅を行先とする最初の n 本の列車を取得するメソッド @return [List <Train>]

# 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
go_to( *stations )
Alias for: bound_for
last_train_depart_after_the_day_change?() click to toggle source

日付が変わった後に終電があるか否かの判定 @return [Boolean] @note 配列の最後の列車が 0:00 - 2:59 の間に出発するか否かによって判定を行う。

# 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 ) click to toggle source

終電の出発前か否かの判定 @param d [DateTime] 時刻の設定(デフォルトは現在時刻) @return [Boolean] @note 配列の最後の列車が出発前か否かによって判定を行う。

# 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 ) click to toggle source
Calls superclass method
# 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 ) click to toggle source

特定の駅に停車する列車を取得するメソッド @param stations [::Array <Station>] 停車する駅 @return [List <Train>] @note 停車駅を複数指定した場合は、指定された【すべて】の駅に停車する列車を取得する。

# 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
Also aliased as: go_to
terminal_stations() click to toggle source

# @note {TokyoMetro::Api::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( station_timetable_info , operation_day_in_db , train_timetables )

self.each do | train |
  train.seed( station_timetable_info , operation_day_in_db , train_timetables )
end

end

# 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 ) click to toggle source

インスタンスの情報を整形した文字列にして返すメソッド @param indent [Integer (>=0)] インデントの幅 @return [String]

# File lib/tokyo_metro/api/station_timetable/info/train_time/list.rb, line 41
def to_strf( indent = 0 )
  super( indent , 1 )
end
will_arrive( d = ::TokyoMetro.time_now )
Alias for: after_now