class TokyoMetro::Static::Fare::Normal

東京メトロの運賃表(普通運賃)を扱うクラス @note 運賃改定などを考慮し、複数の運賃表(改定前と改定後など)を格納することもできる。

Attributes

tables[R]

データベースをもとにした運賃表(現在) @return [::Array <::TokyoMetro::Static::Fare::Normal::Table>]

Public Class Methods

new() click to toggle source

Constructor

# File lib/tokyo_metro/static/fare/normal.rb, line 9
def initialize
  @tables = ::Array.new
  @tables << self.class.normal_fare_table_class.generate_from_yaml( "Fare" , "20140401_normal" , self.class.static_toplevel_namespace.last_revision ).freeze
end
seed() click to toggle source
# File lib/tokyo_metro/static/fare/normal.rb, line 60
def self.seed
  self.instance.current_faretable.seed
end
test() click to toggle source

@!endgroup

# File lib/tokyo_metro/static/fare/normal.rb, line 66
def self.test
  puts self.instance.current_faretable.to_s
end

Public Instance Methods

as_of( date = ::TokyoMetro.time_now ) click to toggle source

指定された日付の運賃表を取得するメソッド @note 運賃改定前後に使うことを念頭に、あらかじめ定義しておく。 @return [Table]

# File lib/tokyo_metro/static/fare/normal.rb, line 21
def as_of( date = ::TokyoMetro.time_now )
  @tables.select { | table | date >= table.valid_from }.min { | a , b | a.valid_from <=> b.valid_from }
end
current_faretable() click to toggle source
# File lib/tokyo_metro/static/fare/normal.rb, line 25
def current_faretable
  table = self.as_of
  raise "Error" if table.nil?
  return table
end
to_a() click to toggle source

自身の情報を配列にして返すメソッド @return [::Array]

# File lib/tokyo_metro/static/fare/normal.rb, line 35
def to_a
  @tables
end
to_h() click to toggle source

自身の情報をハッシュにして返すメソッド @return [Hash]

# File lib/tokyo_metro/static/fare/normal.rb, line 41
def to_h
  h = ::Hash.new
  self.to_a.each do | table |
    h[ table.title.intern ] = table.list
  end
  h
end
to_s( indent = 0 ) click to toggle source

自身の情報を文字列にして返すメソッド @param indent [Integer (>0)] インデントの幅 @return [Hash]

# File lib/tokyo_metro/static/fare/normal.rb, line 52
def to_s( indent = 0 )
  str_ary = ::Array.new
  self.to_a.each do | table |
    str_ary << table.to_s( indent + 2 )
  end
  str_ary.join( "\n" * 2 )
end