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

個別の列車の情報を扱うクラス

Attributes

bound_for[R]

@return [String] 行先 - odpt:Station

car_composition[R]

@return [Integer] 車両数 - xsd:integer @note 駅に停車する車両数が列車毎に異なる場合に格納される。

cars[R]

@return [Integer] 車両数 - xsd:integer @note 駅に停車する車両数が列車毎に異なる場合に格納される。

departure_time[R]

@return [DateTime] 列車の出発時間(ISO8601時刻形式) - odpt:Time @example

05:09
is_last[R]

@return [Boolean] 最終電車か否かの真偽値(最終電車の場合 true) - xsd:boolean

is_origin[R]

@return [Boolean] 始発駅か否かの真偽値(始発駅の場合 true) - xsd:boolean

last_train?[R]

@return [Boolean] 最終電車か否かの真偽値(最終電車の場合 true) - xsd:boolean

notes[R]

@return [String] その他の注釈(接続、通過待ちなど) - xsd:string

start_from_this_station?[R]

@return [Boolean] 始発駅か否かの真偽値(始発駅の場合 true) - xsd:boolean

terminal_station[R]

@return [String] 行先 - odpt:Station

train_type[R]

@return [String] 列車種別 - odpt:TrainType @example

各停 (odpt.TrainType:Local) 、急行 (odpt.TrainType:Express) 、快速 (odpt.TrainType:Rapid) 、特急 (odpt.TrainType:LimitedExpress) など

Public Class Methods

depart_in_midnight?(h) click to toggle source

深夜(日付変更後)の列車か否かの判定 @param h [DateTime] 時刻の設定(「時」を指定する) @return [Boolean]

# File lib/tokyo_metro/api/station_timetable/info/train_time/info.rb, line 248
def self.depart_in_midnight?(h)
  h < ::TokyoMetro::DATE_CHANGING_HOUR
end
factory_for_seeding_this_class() click to toggle source
# File lib/tokyo_metro/api/station_timetable/info/train_time/info.rb, line 239
def self.factory_for_seeding_this_class
  factory_for_seeding_station_train_time
end
factory_for_this_class() click to toggle source

@!group クラスメソッド (2) - データの取得・保存

# File lib/tokyo_metro/api/station_timetable/info/train_time/info.rb, line 235
def self.factory_for_this_class
  factory_for_generating_train_from_hash
end
new( departure_time , terminal_station , train_type , is_last , is_origin , car_composition , notes ) click to toggle source

Constructor

# File lib/tokyo_metro/api/station_timetable/info/train_time/info.rb, line 21
def initialize( departure_time , terminal_station , train_type ,
  is_last , is_origin , car_composition , notes )
  @departure_time = departure_time
  @terminal_station = terminal_station
  @train_type = train_type
  @is_last = is_last
  @is_origin = is_origin
  @car_composition = car_composition
  @notes = notes

  @seed_completed = false
end

Public Instance Methods

==( other ) click to toggle source
# File lib/tokyo_metro/api/station_timetable/info/train_time/info.rb, line 34
def ==( other )
  [ :departure_time , :terminal_station , :train_type , :is_last , :is_origin , :car_composition , :notes ].all?{ | method |
    self.send( method ) == other.send( method )
  }
end
after_now?( time = ::TokyoMetro.time_now ) click to toggle source

指定した時刻より後に出発するか否かの判定 @param time [DateTime] 時刻の設定(デフォルトは現在時刻) @return [Boolean]

# File lib/tokyo_metro/api/station_timetable/info/train_time/info.rb, line 155
def after_now?( time = ::TokyoMetro.time_now )
  self.departure_datetime( time ) <= time
end
Also aliased as: will_arrive?
already_depart?( time = ::TokyoMetro.time_now )
Alias for: before_now?
before_now?( time = ::TokyoMetro.time_now ) click to toggle source

指定した時刻より前に出発するか否かの判定 @param time [DateTime] 時刻の設定(デフォルトは現在時刻) @return [Boolean]

# File lib/tokyo_metro/api/station_timetable/info/train_time/info.rb, line 148
def before_now?( time = ::TokyoMetro.time_now )
  self.departure_datetime( time ) > time
end
Also aliased as: already_depart?
depart_from()
Alias for: platform_number
departure_datetime( time_now = ::TokyoMetro.time_now , change_day_of_midnight_train: true ) click to toggle source

列車の出発時刻を Time のインスタンスとして取得するメソッド @param time_now [DateTime] 現在の時刻(日付の情報を使用するために必要) @param change_day_of_midnight_train [Boolean] false の場合は日付の変更を行わない。(default は true だが、::TokyoMetro::Api::StationTimetable::Info::TrainTime::List#last_train_not_departed_yet? では false に設定している) @return [DateTime] @note 時刻の比較を簡単にする。

# File lib/tokyo_metro/api/station_timetable/info/train_time/info.rb, line 100
def departure_datetime( time_now = ::TokyoMetro.time_now , change_day_of_midnight_train: true )
  train_hour , train_min = self.departure_time_array
  time = DateTime.new( time_now.year , time_now.month , time_now.day , train_hour , train_min , 0 , Rational( 9 , 24 ) )

  unless change_day_of_midnight_train
    return time
  end

  # 【注意】change_day_of_midnight_train が true の場合
  # 以下の処理は、この列車が含まれる時刻表が
  # TokyoMetro::Api::StationTimetable#today_s_timetable などによって、
  # time_now (通常は現在時刻)の時点で適用される時刻表として選択されていることを前提にしている。

  # 日付が変わった直後の深夜の列車か否か
  midnight_train = self.class.depart_in_midnight?( train_hour )

  #-------- 【以下、書きかけ】

  # 現在は深夜か

  unless midnight_train
    return time
  end
  # 出発時刻が 0:00 - 2:59 で、現在時刻が3時を過ぎている場合
  if midnight_train and time_now.hour >= 3
    # 列車の発車の日付は「現在の日付【が】変わった後」の0時~2時となるため、日付を1日進める。
    time.next_day

  # 出発時刻が 3:00 - 22:59 で、現在時刻が3時より前の場合

  # 時刻表に掲載されている時間が2時より後(3時~23時)かつ
  # 現在が0時~2時の場合
  elsif train_hour > 2 and time_now.hour <= 2
    time.prev_day

  elsif train_hour <= 2 and time_now.hour <= 2
    time
  else # train_hour > 2 and time_now.hour > 2
    time
  end

end
departure_time_array() click to toggle source

列車の出発時刻を配列として取得するメソッド @return [::Array <Integer>] @note 「hh:mm」の形(hは時間、mは分)の文字列を、時間と分(それぞれ整数)の配列に変換するメソッド

# File lib/tokyo_metro/api/station_timetable/info/train_time/info.rb, line 91
def departure_time_array
  [ @departure_time.hour , @departure_time.min ]
end
go_to?( *stations )
Alias for: stops_at?
goes_to?( *stations )
Alias for: stops_at?
platform_number() click to toggle source
# File lib/tokyo_metro/api/station_timetable/info/train_time/info.rb, line 76
def platform_number
  info = @notes.find { |i| i.instance_of?( ::TokyoMetro::Api::StationTimetable::Info::TrainTime::Info::Note::PlatformNumber ) }
  if info.nil?
    nil
  else
    info.number
  end
end
Also aliased as: depart_from
stop_at?( *stations )
Alias for: stops_at?
stops_at?( *stations ) click to toggle source

ある駅に停車するか否かを判定するメソッド @param stations [String] 判定する駅名 @return [Boolean] @note 複数指定した場合は、指定された【すべて】の駅に停車する列車を取得する。

# File lib/tokyo_metro/api/station_timetable/info/train_time/info.rb, line 168
def stops_at?( *stations )
  if stations == [ nil ]
    true
  elsif @stops.nil?
    true
  else
    stations.all? { | station |
      ( station.string? and @stops.include?( station ) ) # or ( station.instance_of?( Station ) and @stops.include?( station ) )
    }
  end
end
Also aliased as: stop_at?, goes_to?, go_to?
to_h() click to toggle source

インスタンスの情報をハッシュにして返すメソッド @return [Hash]

# File lib/tokyo_metro/api/station_timetable/info/train_time/info.rb, line 187
def to_h
  h = ::Hash.new

  set_data_to_hash( h , "odpt:departureTime" , @departure_time.strftime( "%H:%M" ) )
  set_data_to_hash( h , "odpt:destinationStation" , @terminal_station )
  set_data_to_hash( h , "odpt:trainType" , @train_type )
  set_data_to_hash( h , "odpt:isLast" , @is_last )
  set_data_to_hash( h , "odpt:isOrigin" , @is_origin )
  set_data_to_hash( h , "odpt:carComposition" , @car_composition )
  set_data_to_hash( h , "odpt:notes" , @notes )

  h
end
to_s( indent = 0 ) click to toggle source

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

# File lib/tokyo_metro/api/station_timetable/info/train_time/info.rb, line 204
def to_s( indent = 0 )
  h = self.to_h
  str_ary = ::Array.new
  str_ary << ( "出発:" + h[ "odpt:departureTime" ] )
  str_ary << ( "行先:"  + h[ "odpt:destinationStation" ] )
  str_ary << ( "種別:"  + h[ "odpt:trainType" ] )

  str_note_ary = ::Array.new
  if h[ "odpt:isLast" ]
    str_note_ary << "【最終】"
  end
  if h[ "odpt:isOrigin" ]
    str_note_ary << "【当駅始発】"
  end
  if h[ "odpt:carComposition" ].integer?
    str_note_ary << "[#{h[ "odpt:carComposition" ]}両編成]"
  end

  str_ary << " " * 3 + str_note_ary.join(" ")

  if h[ "odpt:note" ].present?
    str_ary << " " * 3 + h[ "odpt:note" ]
  end

  str_ary.map { | str | " " * indent + str }.join( "\n" )
end
Also aliased as: to_strf
to_strf( indent = 0 )
Alias for: to_s
will_arrive?( time = ::TokyoMetro.time_now )
Alias for: after_now?