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

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

Overview

Note:

通常は TokyoMetro::Fare::Normal.table から呼び出す。

各料金区間の運賃の配列を扱うクラス

Defined Under Namespace

Classes: List, Pattern

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, ary, from) ⇒ Table

Constructor

Parameters:



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 改定日.

Returns:

  • (::DateTime)

    改定日



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 運賃表の配列.

Returns:



20
21
22
# File 'lib/tokyo_metro/static/fare/normal/table.rb', line 20

def list
  @list
end

#title::String (readonly)

Returns 運賃表のタイトル.

Returns:

  • (::String)

    運賃表のタイトル



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 のデータからインスタンスを作成するメソッド

Parameters:

  • title (::String)

    運賃表のタイトル

  • yaml_file (::String)

    YAML のファイル名

Returns:



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_revisionObject



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

#seedObject



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

運賃表の情報を文字列として返すメソッド

Parameters:

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

    ] インデントの幅

Returns:

  • (::String)


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