Class: TokyoMetro::Api::TrainLocation::Info

Overview

個別の列車のロケーション情報を扱うクラス

Defined Under Namespace

Classes: Delay

列車ロケーション情報のメタデータ (For developers) collapse

列車情報 (For users) collapse

遅延 (For users) collapse

列車ロケーション情報 (For users) collapse

Attributes inherited from MetaClass::Fundamental::Info

#id_urn

遅延情報に関するメソッド (For users) collapse

列車の現在位置に関するメソッド (For users) collapse

Instance Method Summary collapse

Methods included from Modules::Api::Info::Decision::OperatedSection

#marunouchi_main_and_branch_line?, #operated_only_on_chiyoda_branch_line?, #operated_only_on_chiyoda_branch_line_including_invalid?, #operated_only_on_marunouchi_branch_line?, #operated_only_on_marunouchi_branch_line_including_invalid?

Methods included from Modules::Api::Info::Decision::TerminalStation

#bound_for?

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

#bound_for?, #terminating_on_marunouchi_branch_line_including_invalid?, #terminating_on_tokyu_toyoko_or_at_motomachi_chukagai?, #terminating_on_tokyu_toyoko_or_minatomirai_line?

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

#starting_on_marunouchi_branch_line_including_invalid?, #starting_on_tokyu_toyoko_or_at_motomachi_chukagai?, #starting_on_tokyu_toyoko_or_minatomirai_line?

Methods included from Modules::Api::Info::Decision::TrainDirection

#direction_a?, #direction_b?

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

#express?, #limited_express_or_romance_car?, #local?, #romance_car_specific_train?

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::Info::Decision::RomanceCar

#romance_car_on_chiyoda_line?, #romance_car_specific_train_on_chiyoda_line?

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

#toei_mita_line_train_including_on_namboku_line?

Methods included from Modules::Api::Info::ToStringGeneral

#to_s

Methods included from Modules::Api::Info::Validity

#valid?, #validity

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

#to_json

Constructor Details

#initialize(id_urn, same_as, train_number, train_type, dc_date, valid, frequency, railway_line, train_owner, railway_direction, delay, starting_station, terminal_station, from_station, to_station) ⇒ Info

Constructor



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tokyo_metro/api/train_location/info.rb', line 22

def initialize( id_urn , same_as , train_number , train_type , dc_date , valid , frequency ,
  railway_line , train_owner , railway_direction , delay , starting_station , terminal_station , from_station , to_station )
  @id_urn = id_urn
  @same_as = same_as
  @dc_date , @valid , @frequency = dc_date , valid , frequency
  @train_number , @train_type = train_number , train_type
  @railway_line , @train_owner , @railway_direction = railway_line , train_owner , railway_direction
  @delay = delay
  @starting_station , @terminal_station = starting_station , terminal_station
  @from_station , @to_station = from_station , to_station

  # set_train_name
end

Instance Attribute Details

#dc_dateDateTime (readonly)

データ生成時刻 - xsd:dateTime(ISO8601 日付時刻形式をもとに生成した DateTime のインスタンス)

Examples:

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

Returns:

  • (DateTime)


47
48
49
# File 'lib/tokyo_metro/api/train_location/info.rb', line 47

def dc_date
  @dc_date
end

#delayInteger (readonly)

Note:

5分未満は切り捨て

遅延時間(秒) - xsd:integer

Returns:

  • (Integer)


98
99
100
# File 'lib/tokyo_metro/api/train_location/info.rb', line 98

def delay
  @delay
end

#frequencyInteger (readonly)

Note:

指定された秒数以降にリクエストを行うことで、最新値が取得される。

更新頻度(秒) - xsd:integer

Returns:

  • (Integer)


58
59
60
# File 'lib/tokyo_metro/api/train_location/info.rb', line 58

def frequency
  @frequency
end

#from_stationString (readonly)

列車が出発した駅 - odpt:Station

Returns:

  • (String)


104
105
106
# File 'lib/tokyo_metro/api/train_location/info.rb', line 104

def from_station
  @from_station
end

#railway_directionString (readonly)

方面 - odpt:RailDirection

Examples:

odpt.RailDirection:TokyoMetro.Shibuya - 渋谷方面行きを表す

Returns:

  • (String)


91
92
93
# File 'lib/tokyo_metro/api/train_location/info.rb', line 91

def railway_direction
  @railway_direction
end

#railway_lineString (readonly)

鉄道路線ID - odpt:Railway

Returns:

  • (String)


73
74
75
# File 'lib/tokyo_metro/api/train_location/info.rb', line 73

def railway_line
  @railway_line
end

#same_asString (readonly)

Note:

API での命名ルールは「odpt.Train:TokyoMetro.路線名.列車番号」

固有識別子 - URL

Returns:

  • (String)


41
42
43
# File 'lib/tokyo_metro/api/train_location/info.rb', line 41

def same_as
  @same_as
end

#starting_stationString (readonly)

列車の始発駅 - odpt:Station

Returns:

  • (String)


81
82
83
# File 'lib/tokyo_metro/api/train_location/info.rb', line 81

def starting_station
  @starting_station
end

#terminal_stationString (readonly)

列車の終着駅 - odpt:Station

Returns:

  • (String)


85
86
87
# File 'lib/tokyo_metro/api/train_location/info.rb', line 85

def terminal_station
  @terminal_station
end

#to_stationString? (readonly)

列車が向かっている駅 - odpt:Station

Returns:

  • (String)
  • (nil)

    列車が駅に停車している場合は nil



109
110
111
# File 'lib/tokyo_metro/api/train_location/info.rb', line 109

def to_station
  @to_station
end

#train_nameObject (readonly)

Returns the value of attribute train_name.



111
112
113
# File 'lib/tokyo_metro/api/train_location/info.rb', line 111

def train_name
  @train_name
end

#train_numberString (readonly)

列車番号 - xsd:string

Returns:

  • (String)


64
65
66
# File 'lib/tokyo_metro/api/train_location/info.rb', line 64

def train_number
  @train_number
end

#train_ownerString (readonly)

車両の所属会社 - odpt:TrainOwner

Returns:

  • (String)


77
78
79
# File 'lib/tokyo_metro/api/train_location/info.rb', line 77

def train_owner
  @train_owner
end

#train_typeString (readonly)

Note:

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

列車種別 - odpt:TrainType

Returns:

  • (String)


69
70
71
# File 'lib/tokyo_metro/api/train_location/info.rb', line 69

def train_type
  @train_type
end

#validDateTime (readonly)

データ保証期限 - xsd:dateTime(ISO8601 日付時刻形式をもとに生成した DateTime のインスタンス)

Examples:

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

Returns:

  • (DateTime)


53
54
55
# File 'lib/tokyo_metro/api/train_location/info.rb', line 53

def valid
  @valid
end

Instance Method Details

#actual_delayObject



170
171
172
# File 'lib/tokyo_metro/api/train_location/info.rb', line 170

def actual_delay
  @delay
end

#before_decorateObject



119
120
121
# File 'lib/tokyo_metro/api/train_location/info.rb', line 119

def before_decorate
  ::TokyoMetro::Factory::BeforeDecorate::Api::TrainLocation::Info.new( self )
end

#between_station?Boolean

列車が駅間にいるか否かの真偽値(駅間にいる場合は true )

Returns:

  • (Boolean)


196
197
198
# File 'lib/tokyo_metro/api/train_location/info.rb', line 196

def between_station?
  !( now_at_station? )
end

#decorate(request, railway_line) ⇒ Object



115
116
117
# File 'lib/tokyo_metro/api/train_location/info.rb', line 115

def decorate( request , railway_line )
  ::TokyoMetro::Factory::Decorate::Api::TrainLocation::Info.new( request , self , railway_line )
end

#delay_instanceObject



200
201
202
# File 'lib/tokyo_metro/api/train_location/info.rb', line 200

def delay_instance
  ::TokyoMetro::Api::TrainLocation::Info::Delay.new( actual_delay )
end

#delay_now?(delay_minimum_second) ⇒ Boolean

遅延しているか否かを判定するメソッド

Parameters:

  • delay_minimum_second (Integer)

    遅延とみなさない最大の秒数(遅延となる最小の秒数)

Returns:

  • (Boolean)


181
182
183
184
# File 'lib/tokyo_metro/api/train_location/info.rb', line 181

def delay_now?( delay_minimum_second )
  raise "Error" unless delay_minimum_second >= 0
  actual_delay > delay_minimum_second
end

#now_at_station?Boolean

列車が駅に停車中か否かの真偽値(駅に停車中の場合は true )

Returns:

  • (Boolean)


190
191
192
# File 'lib/tokyo_metro/api/train_location/info.rb', line 190

def now_at_station?
  @to_station.nil?
end

#on_schedule?Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/tokyo_metro/api/train_location/info.rb', line 174

def on_schedule?
  actual_delay == 0
end

#to_hHash

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

Returns:

  • (Hash)


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/tokyo_metro/api/train_location/info.rb', line 141

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.to_s )
  set_data_to_hash( h , "dct:valid" , @valid.to_s )
  set_data_to_hash( h , "odpt:frequency" , @frequency )

  set_data_to_hash( h , "odpt:railway" , @railway_line )
  set_data_to_hash( h , "odpt:railDirection" , @railway_direction )
  set_data_to_hash( h , "odpt:trainNumber" , @train_number )
  set_data_to_hash( h , "odpt:trainType" , @train_type )
  set_data_to_hash( h , "odpt.trainOwner" , @train_owner )

  set_data_to_hash( h , "odpt:startingStation" , @starting_sta )
  set_data_to_hash( h , "odpt:terminalStation" , @terminal_sta )

  set_data_to_hash( h , "odpt:delay" , @delay )

  set_data_to_hash( h , "odpt:fromStation" , @from_station )
  set_data_to_hash( h , "odpt:toStation" , @to_station )

  h
end