Class: TokyoMetro::Api::Fare::Info

Overview

2駅間の運賃を扱うクラス

Instance Attribute Summary collapse

Attributes inherited from MetaClass::Fundamental::Info

#id_urn

運賃の情報を取得するメソッド collapse

具体的な運賃を取得するメソッド (1) - 普通運賃 collapse

具体的な運賃を取得するメソッド (2) - 回数券 collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#seed

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

#to_json

Constructor Details

#initialize(id_urn, same_as, dc_date, operator, from_station, to_station, normal_fare) ⇒ Info

Constructor



9
10
11
12
13
14
15
16
17
# File 'lib/tokyo_metro/api/fare/info.rb', line 9

def initialize( id_urn , same_as , dc_date , operator , from_station , to_station , normal_fare )
  @id_urn = id_urn
  @same_as = same_as
  @dc_date = dc_date
  @operator = operator
  @from_station = from_station
  @to_station = to_station
  @normal_fare = normal_fare
end

Instance Attribute Details

#dc_dateString (readonly)

データ生成日時(ISO8601 日付時刻形式)

Returns:

  • (String)


30
31
32
# File 'lib/tokyo_metro/api/fare/info.rb', line 30

def dc_date
  @dc_date
end

#from_stationString (readonly) Also known as: from, from_sta

駅間の始点駅

Returns:

  • (String)


38
39
40
# File 'lib/tokyo_metro/api/fare/info.rb', line 38

def from_station
  @from_station
end

#normal_fare::TokyoMetro::Static::Fare::Normal::Pattern (readonly)

運賃の情報を扱うインスタンス

Returns:

  • (::TokyoMetro::Static::Fare::Normal::Pattern)


46
47
48
# File 'lib/tokyo_metro/api/fare/info.rb', line 46

def normal_fare
  @normal_fare
end

#operatorString (readonly)

運行会社

Returns:

  • (String)


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

def operator
  @operator
end

#same_asString (readonly)

Note:

命名ルールは「odpt.RailwayFare:TokyoMetro.出発駅の路線名.出発駅名.TokyoMetro.到着駅の路線名.到着駅名」

固有識別子

Returns:

  • (String)


26
27
28
# File 'lib/tokyo_metro/api/fare/info.rb', line 26

def same_as
  @same_as
end

#to_stationString (readonly) Also known as: to, to_sta

駅間の終点駅

Returns:

  • (String)


42
43
44
# File 'lib/tokyo_metro/api/fare/info.rb', line 42

def to_station
  @to_station
end

Class Method Details

.attr_namesObject



19
20
21
# File 'lib/tokyo_metro/api/fare/info.rb', line 19

def self.attr_names
  [ :id_urn , :same_as , :dc_date , :operator , :from_station , :to_station , :normal_fare ]
end

Instance Method Details

#child_coupon_ticket_fareInteger

回数券(小児)の発売額

Returns:

  • (Integer)


158
159
160
# File 'lib/tokyo_metro/api/fare/info.rb', line 158

def child_coupon_ticket_fare
  @normal_fare.child_coupon_ticket_fare
end

#child_daytime_coupon_ticket_per_one_pieceInteger

時差回数券(小児・12枚つづり)の1枚あたりの発売額

Returns:

  • (Integer)


188
189
190
# File 'lib/tokyo_metro/api/fare/info.rb', line 188

def child_daytime_coupon_ticket_per_one_piece
  @normal_fare.child_daytime_coupon_ticket_per_one_piece
end

#child_holiday_coupon_ticket_per_one_pieceInteger

土休回数券(小児・14枚つづり)の1枚あたりの発売額

Returns:

  • (Integer)


194
195
196
# File 'lib/tokyo_metro/api/fare/info.rb', line 194

def child_holiday_coupon_ticket_per_one_piece
  @normal_fare.child_holiday_coupon_ticket_per_one_piece
end

#child_ic_card_fareInteger

普通運賃(小児・ICカード)

Returns:

  • (Integer)


144
145
146
# File 'lib/tokyo_metro/api/fare/info.rb', line 144

def child_ic_card_fare
  @normal_fare.child_ic_card_fare
end

#child_normal_coupon_ticket_per_one_pieceInteger

普通回数券(小児・11枚つづり)の1枚あたりの発売額

Returns:

  • (Integer)


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

def child_normal_coupon_ticket_per_one_piece
  @normal_fare.child_normal_coupon_ticket_per_one_piece
end

#child_ticket_fareInteger

普通運賃(小児・切符)

Returns:

  • (Integer)


132
133
134
# File 'lib/tokyo_metro/api/fare/info.rb', line 132

def child_ticket_fare
  @normal_fare.child_ticket_fare
end

#coupon_ticket_fareInteger

回数券(大人)の発売額

Returns:

  • (Integer)


152
153
154
# File 'lib/tokyo_metro/api/fare/info.rb', line 152

def coupon_ticket_fare
  @normal_fare.coupon_ticket_fare
end

#daytime_coupon_ticket_per_one_pieceInteger

時差回数券(大人・12枚つづり)の1枚あたりの発売額

Returns:

  • (Integer)


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

def daytime_coupon_ticket_per_one_piece
  @normal_fare.daytime_coupon_ticket_per_one_piece
end

#from?(*stations) ⇒ Boolean Also known as: is_from?

Parameters:

  • stations (String, Regexp, Array<String or Regexp>)

Returns:

  • (Boolean)


49
50
51
# File 'lib/tokyo_metro/api/fare/info.rb', line 49

def from?( *stations )
  stations.flatten.any? { | station | station === @from_station }
end

#from_or_to?(*stations) ⇒ Boolean Also known as: is_from_or_to?

Returns:

  • (Boolean)


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

def from_or_to?( *stations )
  from?( *stations ) or to?( *stations )
end

#holiday_coupon_ticket_per_one_pieceInteger

土休回数券(大人・14枚つづり)の1枚あたりの発売額

Returns:

  • (Integer)


176
177
178
# File 'lib/tokyo_metro/api/fare/info.rb', line 176

def holiday_coupon_ticket_per_one_piece
  @normal_fare.holiday_coupon_ticket_per_one_piece
end

#ic_card_fareInteger

普通運賃(大人・ICカード)

Returns:

  • (Integer)


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

def ic_card_fare
  @normal_fare.ic_card_fare
end

#normal_coupon_ticket_per_one_pieceInteger

普通回数券(大人・11枚つづり)の1枚あたりの発売額

Returns:

  • (Integer)


164
165
166
# File 'lib/tokyo_metro/api/fare/info.rb', line 164

def normal_coupon_ticket_per_one_piece
  @normal_fare.normal_coupon_ticket_per_one_piece
end

#ticket_fareInteger

普通運賃(大人・切符)

Returns:

  • (Integer)


126
127
128
# File 'lib/tokyo_metro/api/fare/info.rb', line 126

def ticket_fare
  @normal_fare.ticket_fare
end

#to?(*stations) ⇒ Boolean Also known as: is_to?

Parameters:

  • stations (String, Regexp, Array<String or Regexp>)

Returns:

  • (Boolean)


54
55
56
# File 'lib/tokyo_metro/api/fare/info.rb', line 54

def to?( *stations )
  stations.flatten.any? { | station | station === @to_station }
end

#to_hHash

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

Returns:

  • (Hash)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/tokyo_metro/api/fare/info.rb', line 76

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 , "odpt:operator" , @operator )
  set_data_to_hash( h , "odpt:fromStation" , @from_station )
  set_data_to_hash( h , "odpt:toStation" , @to_station )

  set_data_to_hash( h , "odpt:ticketFare" , self.ticket_fare )
  set_data_to_hash( h , "odpt:childTicketFare" , self.child_ticket_fare )
  set_data_to_hash( h , "odpt:icCardFare" , self.ic_card_fare )
  set_data_to_hash( h , "odpt:childIcCardFare" , self.child_ic_card_fare )

  h
end

#to_s(indent = 0) ⇒ String Also known as: to_strf

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

Parameters:

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

    ] インデントの幅

Returns:

  • (String)


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/tokyo_metro/api/fare/info.rb', line 97

def to_s ( indent = 0 )
  h = self.to_h
  hash_keys_ary_1 = [ "\@id" , "owl:sameAs" , "dc:date" ]
  hash_keys_ary_2 = [ "odpt:operator" , "odpt:fromStation" , "odpt:toStation" ]
  hash_keys_ary_3 = [ "odpt:ticketFare" , "odpt:childTicketFare" , "odpt:icCardFare" , "odpt:childIcCardFare" ]

  str_ary = ::Array.new
  str_ary << " " * indent + "#{@from_station} - #{@to_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 << ( " " * ( indent + 2 ) + key.ljust(32) + h[ key ].to_strf )
      end
    end
    str_ary << ""
  end

  str_ary << @normal_fare.to_s_table( indent + 2 )
  str_ary.join( "\n" )
end