Class: TokyoMetro::Api::StationTimetable::Info
- Inherits:
-
MetaClass::NotRealTime::Info
- Object
- MetaClass::Fundamental::Info
- MetaClass::NotRealTime::Info
- TokyoMetro::Api::StationTimetable::Info
- Includes:
- ClassNameLibrary::Api::StationTimetable, Modules::Api::Info::Decision::CurrentStation, Modules::Api::Info::Decision::RailwayLine, Modules::Common::Info::Decision::CompareBase, Modules::Common::Info::Decision::SameAs, Modules::Common::ToFactory::Seed::Info
- Defined in:
- lib/tokyo_metro/api/station_timetable/info.rb
Overview
個別の駅・路線・方面の時刻表を扱うクラス
Defined Under Namespace
Modules: Fundamental, TrainTime Classes: Hash
時刻表のメタデータ (For developers) collapse
-
#dc_date ⇒ DateTime
readonly
データ生成時刻(ISO8601日付時刻形式) - xsd:dateTime.
-
#same_as ⇒ String
readonly
固有識別子 - URL.
時刻表のメタデータ (For users) collapse
-
#fundamental_infos ⇒ String
readonly
方面 - odpt:RailDirection attr_reader :railway_direction.
時刻表データ(配列) collapse
-
#holidays ⇒ Info::Train::List <Info::Train::Info (odpt:StationTimetableObject)>
(also: #sundays)
readonly
休日ダイヤ.
-
#saturdays ⇒ Info::Train::List <Info::Train::Info (odpt:StationTimetableObject)>
readonly
土曜ダイヤ.
-
#weekdays ⇒ Info::Train::List <Info::Train::Info (odpt:StationTimetableObject)>
(also: #fridays)
readonly
平日ダイヤ.
Attributes inherited from MetaClass::Fundamental::Info
時刻表データ(配列) collapse
- #combination_of_timetable_types_and_operation_days ⇒ Object
- #terminal_stations(*days) ⇒ Object
- #timetables ⇒ Object
時刻表の情報の取得 (1) collapse
-
#to_h ⇒ Hash
インスタンスの情報をハッシュにして返すメソッド.
-
#to_s ⇒ String
インスタンスの情報を文字列にして返すメソッド.
-
#to_strf ⇒ String
インスタンスの情報を整形した文字列にして返すメソッド.
時刻表の情報の取得 (2) collapse
-
#timetable_hash(*variables, first: false, last: false) ⇒ Hash
平日・土曜・休日それぞれの時刻表データを値とするハッシュを返すメソッド.
指定された条件に合った時刻表を返すメソッド collapse
-
#after_now(*variables, date: ::TokyoMetro.time_now) ⇒ List <Train>, Hash
指定された時刻より後に発車する列車を取得するメソッド.
-
#before_now(*variables, date: ::TokyoMetro.time_now) ⇒ List <Train>, Hash
指定された時刻より前に発車する列車を取得するメソッド.
-
#bound_for(*variables, stations: nil, date: ::TokyoMetro.time_now) ⇒ List <Train>
(also: #go_to)
特定の行先の列車を取得するメソッド.
-
#stop_at(*variables, stations: nil, date: ::TokyoMetro.time_now) ⇒ List <Train>
特定の駅に停車する列車を取得するメソッド.
-
#today_s_timetable(d = ::TokyoMetro.time_now, to_hash: false) ⇒ Info::List, Info::Hash
指定された日付の時刻表を返すメソッド.
クラスメソッド (3) - 時刻表の種類 collapse
-
.type_of_timetables ⇒ ::Array <Symbol>
許容される時刻表の種類(Info クラスのインスタンス変数).
その他 collapse
-
#color_in_css_class ⇒ String
CSS ファイル内で使用する路線の色を取得するメソッド.
- #instance_in_db ⇒ Object
- #seed_train_times(train_timetables) ⇒ Object
Instance Method Summary collapse
-
#initialize(id_urn, same_as, dc_date, station_timetable_fundamental_infos, weekdays, saturdays, holidays) ⇒ Info
constructor
Constructor.
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
Methods included from Modules::Common::Info::Decision::SameAs
Methods included from Modules::Api::Info::ToJson
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 , , weekdays , saturdays , holidays ) @id_urn = id_urn @same_as = same_as @dc_date = dc_date @fundamental_infos = @weekdays = weekdays @saturdays = saturdays @holidays = holidays puts @same_as end |
Instance Attribute Details
#dc_date ⇒ DateTime (readonly)
データ生成時刻(ISO8601日付時刻形式) - xsd:dateTime
40 41 42 |
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 40 def dc_date @dc_date end |
#fundamental_infos ⇒ String (readonly)
方面 - odpt:RailDirection attr_reader :railway_direction
60 61 62 |
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 60 def fundamental_infos @fundamental_infos end |
#holidays ⇒ Info::Train::List <Info::Train::Info (odpt:StationTimetableObject)> (readonly) Also known as: sundays
拡張性を考慮し、#holidays の別名として #sundays を定義する。(例:都営バス 品98)
休日ダイヤ
76 77 78 |
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 76 def holidays @holidays end |
#same_as ⇒ String (readonly)
命名ルールは「odpt.StationTimetable:TokyoMetro.路線名.駅名.方面名」
固有識別子 - URL
34 35 36 |
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 34 def same_as @same_as end |
#saturdays ⇒ Info::Train::List <Info::Train::Info (odpt:StationTimetableObject)> (readonly)
土曜ダイヤ
71 72 73 |
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 71 def saturdays @saturdays end |
#weekdays ⇒ Info::Train::List <Info::Train::Info (odpt:StationTimetableObject)> (readonly) Also known as: fridays
拡張性を考慮し、#weekdays の別名として #friday を定義する。(例:JR埼京線)
平日ダイヤ
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>
取りうる値は、原則として :weekdays(平日), :satudays(土曜), :holidays(休日)である。
特殊なダイヤや他の鉄道・バスへの拡張性を考慮し、:fridays, :sundays(日曜…休日ダイヤと日曜ダイヤが異なる場合を考慮), :no_school_days(学休日), :new_year(年末年始), :all_night(終夜運転), :extra_operation(臨時ダイヤ), :business_use(業務用) , :maintainance(線路保守・システム保守・テスト用), :emergency(災害時・緊急時用)も認める設定とする。
許容される時刻表の種類(Info クラスのインスタンス変数)
247 248 249 250 251 252 253 |
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 247 def self. [ :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
指定された時刻より後に発車する列車を取得するメソッド
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
指定された時刻より前に発車する列車を取得するメソッド
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
行先を複数指定した場合は、指定された【いずれか】の駅を行先とする列車を取得する。
特定の行先の列車を取得するメソッド
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_class ⇒ String
CSS ファイル内で使用する路線の色を取得するメソッド
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_days ⇒ Object
105 106 107 108 109 110 |
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 105 def [ [ @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_db ⇒ Object
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( ) = ::TokyoMetro::Factory::Seed::Api::StationTrainTime::TrainInStationTimetable::StationTimetableInfo.new( self ) # 各曜日の時刻の処理〈ここから〉 .each do | , operation_day_in_db | .seed( , operation_day_in_db , ) end # 各曜日の時刻の処理〈ここまで〉 return nil end |
#stop_at(*variables, stations: nil, date: ::TokyoMetro.time_now) ⇒ List <Train>
停車駅を複数指定した場合は、指定された【すべて】の駅に停車する列車を取得する。
特定の駅に停車する列車を取得するメソッド
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 = end t.map( &:terminal_stations ).flatten.sort.uniq end |
#timetable_hash(*variables, first: false, last: false) ⇒ Hash
variables に何も指定しなかった場合は【すべて】のデータを格納する。
平日・土曜・休日それぞれの時刻表データを値とするハッシュを返すメソッド
178 179 180 181 182 183 184 185 |
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 178 def ( *variables , first: false , last: false ) h = ::TokyoMetro::Api::StationTimetable::Info::Hash.new weekdays , satudays , holidays = ( variables ) ( h , "odpt:weekdays" , @weekdays , weekdays , first , last ) ( h , "odpt:saturdays" , @saturdays , saturdays , first , last ) ( h , "odpt:holidays" , @holidays , holidays , first , last ) h end |
#timetables ⇒ Object
92 93 94 |
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 92 def [ @weekdays , @saturdays , @holidays ] end |
#to_h ⇒ Hash
インスタンスの情報をハッシュにして返すメソッド
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_s ⇒ String
#to_strf の alias として定義する。
インスタンスの情報を文字列にして返すメソッド
138 139 140 |
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 138 def to_s self.to_strf end |
#to_strf ⇒ 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
指定された日付の時刻表を返すメソッド
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/tokyo_metro/api/station_timetable/info.rb', line 194 def ( d = ::TokyoMetro.time_now , to_hash: false ) raise "Error" unless d.instance_of?( ::DateTime ) = (d) = self.send( ) unless to_hash else self.( ) end end |