Class: TokyoMetro::Api::StationTimetable::Info::TrainTime::List

Inherits:
MetaClass::Fundamental::List show all
Includes:
ClassNameLibrary::Api::StationTimetable, Modules::Common::ToFactory::Seed::List
Defined in:
lib/tokyo_metro/api/station_timetable/info/train_time/list.rb

Overview

個別の列車の情報の配列

時刻表の情報の取得 collapse

列車の出発時刻に関するメソッド collapse

列車の行先に関するメソッド collapse

列車の停車駅に関するメソッド collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MetaClass::Fundamental::List

#find_by_same_as

Class Method Details

.factory_for_seeding_this_classObject



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

指定された時刻より後に出発する列車を取得するメソッド

Parameters:

  • d (DateTime) (defaults to: ::TokyoMetro.time_now)

    時刻の設定(デフォルトは現在時刻)

Returns:



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

指定された時刻より前に出発する列車を取得するメソッド

Parameters:

  • d (DateTime) (defaults to: ::TokyoMetro.time_now)

    時刻の設定(デフォルトは現在時刻)

Returns:



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>

Note:

行先を複数指定した場合は、指定された【いずれか】の駅を行先とする列車を取得する。

特定の行先の列車を取得するメソッド

Parameters:

  • stations (::Array <Station>)

    行先

Returns:

  • (::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 本の列車を取得するメソッド

Returns:



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

Note:

配列の最後の列車が 0:00 - 2:59 の間に出発するか否かによって判定を行う。

日付が変わった後に終電があるか否かの判定

Returns:

  • (Boolean)


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

Note:

配列の最後の列車が出発前か否かによって判定を行う。

終電の出発前か否かの判定

Parameters:

  • d (DateTime) (defaults to: ::TokyoMetro.time_now)

    時刻の設定(デフォルトは現在時刻)

Returns:

  • (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

Note:

停車駅を複数指定した場合は、指定された【すべて】の駅に停車する列車を取得する。

特定の駅に停車する列車を取得するメソッド

Parameters:

  • stations (::Array <Station>)

    停車する駅

Returns:



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_stationsObject

# @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( 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


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

インスタンスの情報を整形した文字列にして返すメソッド

Parameters:

  • indent (Integer (>=0) (defaults to: 0)

    ] インデントの幅

Returns:

  • (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