Class: TokyoMetro::Api::StationTimetable::Info

Overview

個別の駅・路線・方面の時刻表を扱うクラス

Defined Under Namespace

Modules: Fundamental, TrainTime Classes: Hash

時刻表のメタデータ (For developers) collapse

時刻表のメタデータ (For users) collapse

時刻表データ(配列) collapse

Attributes inherited from MetaClass::Fundamental::Info

#id_urn

時刻表データ(配列) collapse

時刻表の情報の取得 (1) collapse

時刻表の情報の取得 (2) collapse

指定された条件に合った時刻表を返すメソッド collapse

クラスメソッド (3) - 時刻表の種類 collapse

その他 collapse

Instance Method Summary collapse

Methods included from Modules::Common::Info::Decision::RailwayLine

#on_marunouchi_line_including_branch?, #on_namboku_or_toei_mita_line?, #on_toei_mita_line?, #on_yurakucho_or_fukutoshin_line?

Methods included from Modules::Common::ToFactory::Seed::Info

#seed

Methods included from Modules::Common::Info::Decision::SameAs

#same_as?

Methods included from Modules::Api::Info::ToJson

#to_json

Constructor Details

#initialize(id_urn, same_as, dc_date, station_timetable_fundamental_infos, weekdays, saturdays, holidays) ⇒ Info

Constructor



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 13

def initialize( id_urn , same_as , dc_date , station_timetable_fundamental_infos ,
  weekdays , saturdays , holidays )

  @id_urn = id_urn
  @same_as = same_as
  @dc_date = dc_date

  @fundamental_infos = station_timetable_fundamental_infos

  @weekdays = weekdays
  @saturdays = saturdays
  @holidays = holidays

  puts @same_as
end

Instance Attribute Details

#dc_dateDateTime (readonly)

データ生成時刻(ISO8601日付時刻形式) - xsd:dateTime

Examples:

2013–01–13T15:10:00+09:00

Returns:

  • (DateTime)


40
41
42
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 40

def dc_date
  @dc_date
end

#fundamental_infosString (readonly)

方面 - odpt:RailDirection attr_reader :railway_direction

Returns:

  • (String)


60
61
62
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 60

def fundamental_infos
  @fundamental_infos
end

#holidaysInfo::Train::List <Info::Train::Info (odpt:StationTimetableObject)> (readonly) Also known as: sundays

Note:

拡張性を考慮し、#holidays の別名として #sundays を定義する。(例:都営バス 品98)

休日ダイヤ

Returns:

  • (Info::Train::List <Info::Train::Info (odpt:StationTimetableObject)>)


76
77
78
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 76

def holidays
  @holidays
end

#same_asString (readonly)

Note:

命名ルールは「odpt.StationTimetable:TokyoMetro.路線名.駅名.方面名」

固有識別子 - URL

Returns:

  • (String)


34
35
36
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 34

def same_as
  @same_as
end

#saturdaysInfo::Train::List <Info::Train::Info (odpt:StationTimetableObject)> (readonly)

土曜ダイヤ

Returns:

  • (Info::Train::List <Info::Train::Info (odpt:StationTimetableObject)>)


71
72
73
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 71

def saturdays
  @saturdays
end

#weekdaysInfo::Train::List <Info::Train::Info (odpt:StationTimetableObject)> (readonly) Also known as: fridays

Note:

拡張性を考慮し、#weekdays の別名として #friday を定義する。(例:JR埼京線)

平日ダイヤ

Returns:

  • (Info::Train::List <Info::Train::Info (odpt:StationTimetableObject)>)


67
68
69
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 67

def weekdays
  @weekdays
end

Class Method Details

.type_of_timetables::Array <Symbol>

Note:

取りうる値は、原則として :weekdays(平日), :satudays(土曜), :holidays(休日)である。

Note:

特殊なダイヤや他の鉄道・バスへの拡張性を考慮し、:fridays, :sundays(日曜…休日ダイヤと日曜ダイヤが異なる場合を考慮), :no_school_days(学休日), :new_year(年末年始), :all_night(終夜運転), :extra_operation(臨時ダイヤ), :business_use(業務用) , :maintainance(線路保守・システム保守・テスト用), :emergency(災害時・緊急時用)も認める設定とする。

許容される時刻表の種類(Info クラスのインスタンス変数)

Returns:

  • (::Array <Symbol>)


247
248
249
250
251
252
253
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 247

def self.type_of_timetables
  [
    :weekdays , :satudays , :holidays ,
    :fridays , :sundays ,
    :no_school_days , :new_year , :all_night , :extra_operation , :business_use , :maintainance , :emergency
  ]
end

Instance Method Details

#after_now(*variables, date: ::TokyoMetro.time_now) ⇒ List <Train>, Hash

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

Parameters:

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

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

  • variables (::Array)

    時刻を取得する曜日の設定【可変長引数】

Returns:

  • (List <Train>)

    variables に何も指定しなかった場合 - 【メソッドを実行した日】についてのデータを配列で返す。

  • (Hash)

    variables にオプション (:weekdays , :saturdays , :holidays) を指定した場合 - 【指定された曜日】についてのデータをハッシュで返す。



219
220
221
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 219

def after_now( *variables , date: ::TokyoMetro.time_now )
  get_specific_datas_as_for_date( :after_now , variables , date )
end

#before_now(*variables, date: ::TokyoMetro.time_now) ⇒ List <Train>, Hash

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

Parameters:

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

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

  • variables (::Array)

    時刻を取得する曜日の設定【可変長引数】

Returns:

  • (List <Train>)

    variables に何も指定しなかった場合 - 【メソッドを実行した日】についてのデータを配列で返す。

  • (Hash)

    variables にオプション (:weekdays , :saturdays , :holidays) を指定した場合 - 【指定された曜日】についてのデータをハッシュで返す。



210
211
212
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 210

def before_now( *variables , date: ::TokyoMetro.time_now )
  get_specific_datas_as_for_date( :before_now , variables , date )
end

#bound_for(*variables, stations: nil, date: ::TokyoMetro.time_now) ⇒ List <Train> Also known as: go_to

Note:

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

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

Parameters:

  • stations (::Array <Station>) (defaults to: nil)

    行先

Returns:



227
228
229
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 227

def bound_for( *variables , stations: nil , date: ::TokyoMetro.time_now )
  get_specific_datas_as_for_stations( :bound_for , variables , stations , date )
end

#color_in_css_classString

CSS ファイル内で使用する路線の色を取得するメソッド

Returns:

  • (String)


259
260
261
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 259

def color_in_css_class
  ::TokyoMetro::Search::Line.color_in_css_class( @railway_line )
end

#combination_of_timetable_types_and_operation_daysObject



105
106
107
108
109
110
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 105

def combination_of_timetable_types_and_operation_days
  [
    [ @weekdays , ::OperationDay.find_by_name_en( ::TokyoMetro::Static.operation_days.weekday.en ) ] ,
    [ @holidays , ::OperationDay.find_by_name_en( ::TokyoMetro::Static.operation_days.saturday_and_holiday.en ) ]
  ]
end

#instance_in_dbObject



263
264
265
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 263

def instance_in_db
  ::StationTimetable.find_by_same_as( @same_as )
end

#seed_train_times(train_timetables) ⇒ Object



276
277
278
279
280
281
282
283
284
285
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 276

def seed_train_times( train_timetables )
  station_timetable_info = ::TokyoMetro::Factory::Seed::Api::StationTrainTime::TrainInStationTimetable::StationTimetableInfo.new( self )

  # 各曜日の時刻の処理〈ここから〉
  combination_of_timetable_types_and_operation_days.each do | station_timetable_in_a_day , operation_day_in_db |
    station_timetable_in_a_day.seed( station_timetable_info , operation_day_in_db , train_timetables )
  end
  # 各曜日の時刻の処理〈ここまで〉
  return nil
end

#stop_at(*variables, stations: nil, date: ::TokyoMetro.time_now) ⇒ List <Train>

Note:

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

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

Parameters:

  • stations (::Array <Station>) (defaults to: nil)

    停車駅

Returns:



235
236
237
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 235

def stop_at( *variables , stations: nil , date: ::TokyoMetro.time_now )
  get_specific_datas_as_for_stations( :stop_at , variables , stations , date )
end

#terminal_stations(*days) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 96

def terminal_stations( *days )
  if days.present?
    t = days.map { | day_type | self.send( day_type ) }
  else
    t = timetables
  end
  t.map( &:terminal_stations ).flatten.sort.uniq
end

#timetable_hash(*variables, first: false, last: false) ⇒ Hash

Note:

variables に何も指定しなかった場合は【すべて】のデータを格納する。

平日・土曜・休日それぞれの時刻表データを値とするハッシュを返すメソッド

Parameters:

  • variables (::Array <Symbol>)

    ハッシュに格納するデータ (:weekdays , :saturdays , :holidays) を指定する。【可変長引数】

Returns:



178
179
180
181
182
183
184
185
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 178

def timetable_hash( *variables , first: false , last: false )
  h = ::TokyoMetro::Api::StationTimetable::Info::Hash.new
  weekdays , satudays , holidays = timetable_hash_set_settings( variables )
  timetable_hash_set_data_to_hash( h , "odpt:weekdays" , @weekdays , weekdays , first , last )
  timetable_hash_set_data_to_hash( h , "odpt:saturdays" , @saturdays , saturdays , first , last )
  timetable_hash_set_data_to_hash( h , "odpt:holidays" , @holidays , holidays , first , last )
  h
end

#timetablesObject



92
93
94
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 92

def timetables
  [ @weekdays , @saturdays , @holidays ]
end

#to_hHash

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

Returns:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 116

def to_h
  h = Hash.new

  set_data_to_hash( h , "\@id" , @id_urn )
  set_data_to_hash( h , "owl:sameAs" , @same_as )
  set_data_to_hash( h , "dc:date" , @dc_date )

  set_data_to_hash( h , "odpt:operator" , @operator )
  set_data_to_hash( h , "odpt:railway" , @railway_line )
  set_data_to_hash( h , "odpt:station" , @station )
  set_data_to_hash( h , "odpt:railDirection" , @railway_direction )

  set_data_to_hash( h , "odpt:weekdays" , @weekdays )
  set_data_to_hash( h , "odpt:saturdays" , @saturdays )
  set_data_to_hash( h , "odpt:holidays" , @holidays )

  h
end

#to_sString

Note:

#to_strf の alias として定義する。

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

Returns:

  • (String)


138
139
140
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 138

def to_s
  self.to_strf
end

#to_strfString

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

Returns:

  • (String)


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 144

def to_strf
  h = self.to_h
  hash_keys_ary_1 = [ "\@id" , "owl:sameAs" , "dc:date" ]
  hash_keys_ary_2 = [ "odpt:operator" , "odpt:railway" , "odpt:station" , "odpt:railDirection" ]
  hash_keys_ary_3 = [ "odpt:weekdays" , "odpt:saturdays" , "odpt:holidays" ]

  str_ary = ::Array.new
  str_ary << "#{@station}"
  str_ary << ""

  [ hash_keys_ary_1 , hash_keys_ary_2 ].each do | hash_keys_ary |
    hash_keys_ary.each do | key |
      if h[ key ].present?
        str_ary << ( " " * 2 + key.ljust(32) + h[ key ].to_s )
      end
    end
    str_ary << ""
  end

  str_ary << " " * 2 + "○ Timetable"
  hash_keys_ary_3.each do | key |
    str_ary << ( " " * 4 + key )
    str_ary << h[ key ].to_strf(6)
  end

  str_ary.join( "\n" )
end

#today_s_timetable(d = ::TokyoMetro.time_now, to_hash: false) ⇒ Info::List, Info::Hash

指定された日付の時刻表を返すメソッド

Parameters:

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

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

  • to_hash (Boolean) (defaults to: false)

    返す値を Info::Hash のインスタンスにするか否かの設定

Returns:

  • (Info::List)

    to_hash を false (default) にした場合

  • (Info::Hash)

    to_hash を true にした場合



194
195
196
197
198
199
200
201
202
203
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 194

def today_s_timetable( d = ::TokyoMetro.time_now , to_hash: false )
  raise "Error" unless d.instance_of?( ::DateTime )
  timetable_v = today_s_timetable_varible(d)
  timetable = self.send( timetable_v )
  unless to_hash
    timetable
  else
    self.timetable_hash( timetable_v )
  end
end