Class: TokyoMetro::Static::Fare::Normal::Table
- Inherits:
-
Object
- Object
- TokyoMetro::Static::Fare::Normal::Table
- Includes:
- ClassNameLibrary::Static::Fare
- Defined in:
- lib/tokyo_metro/static/fare/normal/table.rb
Overview
Note:
通常は TokyoMetro::Fare::Normal.table から呼び出す。
各料金区間の運賃の配列を扱うクラス
Defined Under Namespace
Instance Attribute Summary collapse
-
#from ⇒ ::DateTime
(also: #valid_from)
readonly
改定日.
-
#list ⇒ ::TokyoMetro::Static::Fare::Normal::Table::List
readonly
運賃表の配列.
-
#title ⇒ ::String
readonly
運賃表のタイトル.
Class Method Summary collapse
-
.generate_from_yaml(title, yaml_file, from) ⇒ ::TokyoMetro::Static::Fare::Normal::Table
YAML のデータからインスタンスを作成するメソッド.
Instance Method Summary collapse
- #date_of_revision ⇒ Object
-
#initialize(title, ary, from) ⇒ Table
constructor
Constructor.
- #seed ⇒ Object
-
#to_s(indent = 0) ⇒ ::String
(also: #to_strf)
運賃表の情報を文字列として返すメソッド.
Constructor Details
#initialize(title, ary, from) ⇒ Table
Constructor
11 12 13 14 15 |
# File 'lib/tokyo_metro/static/fare/normal/table.rb', line 11 def initialize( title , ary , from ) @title = title @list = ary @from = from end |
Instance Attribute Details
#from ⇒ ::DateTime (readonly) Also known as: valid_from
Returns 改定日.
22 23 24 |
# File 'lib/tokyo_metro/static/fare/normal/table.rb', line 22 def from @from end |
#list ⇒ ::TokyoMetro::Static::Fare::Normal::Table::List (readonly)
Returns 運賃表の配列.
20 21 22 |
# File 'lib/tokyo_metro/static/fare/normal/table.rb', line 20 def list @list end |
#title ⇒ ::String (readonly)
Returns 運賃表のタイトル.
18 19 20 |
# File 'lib/tokyo_metro/static/fare/normal/table.rb', line 18 def title @title end |
Class Method Details
.generate_from_yaml(title, yaml_file, from) ⇒ ::TokyoMetro::Static::Fare::Normal::Table
YAML のデータからインスタンスを作成するメソッド
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tokyo_metro/static/fare/normal/table.rb', line 50 def self.generate_from_yaml( title , yaml_file , from ) ary = self.normal_fare_table_list_class.new ::YAML.load_file( "#{db_dirname}/#{yaml_file}.yaml" ).each do |h| fares = [ "ticket_fare" , "child_ticket_fare" , "ic_card_fare" , "child_ic_card_fare" ].map { | key | h[ key ] } ary << self.normal_fare_table_pattern_class.new( *fares ).freeze end raise_error_of_element( ary ) self.new( title , ary , from ) end |
Instance Method Details
#date_of_revision ⇒ Object
38 39 40 |
# File 'lib/tokyo_metro/static/fare/normal/table.rb', line 38 def date_of_revision ::Date.new( @from.year , @from.month , @from.day ) end |
#seed ⇒ Object
42 43 44 |
# File 'lib/tokyo_metro/static/fare/normal/table.rb', line 42 def seed @list.seed( date_of_revision , ::Operator.find_by_same_as( "odpt.Operator:TokyoMetro" ).id ) end |
#to_s(indent = 0) ⇒ ::String Also known as: to_strf
運賃表の情報を文字列として返すメソッド
28 29 30 31 32 33 34 35 |
# File 'lib/tokyo_metro/static/fare/normal/table.rb', line 28 def to_s( indent = 0 ) str_ary = ::Array.new str_ary << " " * indent + "○ #{@title} (from #{ @from.strftime("%Y.%m.%d") })" str_ary << @list.to_s( indent + 2 ) str_ary.join( "\n" * 2 ) end |