class TokyoMetro::Static::Fare::Normal::Table

各料金区間の運賃の配列を扱うクラス @note 通常は TokyoMetro::Fare::Normal.table から呼び出す。

Attributes

from[R]

@return [::DateTime] 改定日

list[R]

@return [::TokyoMetro::Static::Fare::Normal::Table::List] 運賃表の配列

title[R]

@return [::String] 運賃表のタイトル

valid_from[R]

@return [::DateTime] 改定日

Public Class Methods

generate_from_yaml( title , yaml_file , from ) click to toggle source

YAML のデータからインスタンスを作成するメソッド @param title [::String] 運賃表のタイトル @param yaml_file [::String] YAML のファイル名 @return [::TokyoMetro::Static::Fare::Normal::Table]

# 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
new( title , ary , from ) click to toggle source

Constructor @param title [::String] 運賃表のタイトル @param list [::TokyoMetro::Static::Fare::Normal::Table::List] 運賃表の配列 @param from [::DateTime] 改定日

# File lib/tokyo_metro/static/fare/normal/table.rb, line 11
def initialize( title , ary , from )
  @title = title
  @list = ary
  @from = from
end

Private Class Methods

db_dirname() click to toggle source

データを保存するディレクトリ @return [::String]

# File lib/tokyo_metro/static/fare/normal/table.rb, line 78
def db_dirname
  "#{ ::TokyoMetro::dictionary_dir }/fare"
end
raise_error_of_element( ary ) click to toggle source

配列の要素をチェックするメソッド @param ary [::Array] チェックする配列 @return [nil]

# File lib/tokyo_metro/static/fare/normal/table.rb, line 69
def raise_error_of_element( ary )
  unless ary.all?{ |i| i.instance_of?( normal_fare_table_pattern_class ) }
    raise "Error"
  end
  return nil
end

Public Instance Methods

date_of_revision() click to toggle source
# 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() click to toggle source
# 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 ) click to toggle source

運賃表の情報を文字列として返すメソッド @param indent [::Integer (>0)] インデントの幅 @return [::String]

# 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
Also aliased as: to_strf
to_strf( indent = 0 )
Alias for: to_s