Class: TokyoMetro::Static::Fare::Normal

Inherits:
Object
  • Object
show all
Includes:
Singleton, ClassNameLibrary::Static::Fare
Defined in:
lib/tokyo_metro/static/fare/normal.rb

Overview

Note:

運賃改定などを考慮し、複数の運賃表(改定前と改定後など)を格納することもできる。

東京メトロの運賃表(普通運賃)を扱うクラス

Defined Under Namespace

Classes: Table

Instance Attribute Summary collapse

自身の情報を変換して取得するメソッド collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNormal

Constructor



9
10
11
12
# 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

Instance Attribute Details

#tables::Array <::TokyoMetro::Static::Fare::Normal::Table> (readonly)

データベースをもとにした運賃表(現在)



16
17
18
# File 'lib/tokyo_metro/static/fare/normal.rb', line 16

def tables
  @tables
end

Class Method Details

.seedObject



60
61
62
# File 'lib/tokyo_metro/static/fare/normal.rb', line 60

def self.seed
  self.instance.current_faretable.seed
end

.testObject



66
67
68
# File 'lib/tokyo_metro/static/fare/normal.rb', line 66

def self.test
  puts self.instance.current_faretable.to_s
end

Instance Method Details

#as_of(date = ::TokyoMetro.time_now) ⇒ Table

Note:

運賃改定前後に使うことを念頭に、あらかじめ定義しておく。

指定された日付の運賃表を取得するメソッド

Returns:



21
22
23
# 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_faretableObject



25
26
27
28
29
# 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::Array

自身の情報を配列にして返すメソッド

Returns:

  • (::Array)


35
36
37
# File 'lib/tokyo_metro/static/fare/normal.rb', line 35

def to_a
  @tables
end

#to_hHash

自身の情報をハッシュにして返すメソッド

Returns:

  • (Hash)


41
42
43
44
45
46
47
# 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) ⇒ Hash

自身の情報を文字列にして返すメソッド

Parameters:

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

    ] インデントの幅

Returns:

  • (Hash)


52
53
54
55
56
57
58
# 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