Class: Zakuro::Japan::Gengou::Resource::Parser::GengouSetParser
- Inherits:
-
Object
- Object
- Zakuro::Japan::Gengou::Resource::Parser::GengouSetParser
- Defined in:
- lib/zakuro/era/japan/gengou/resource/parser.rb
Overview
GengouSetParser 元号セット情報の検証/展開
Instance Attribute Summary collapse
-
#id ⇒ String
readonly
元号セットID.
-
#last_date ⇒ Hash<String, String>
readonly
終了日.
-
#last_year ⇒ Hash<String, String>
readonly
終了年.
-
#list ⇒ Array<Hash<String, String>>
readonly
元号情報.
-
#name ⇒ String
readonly
元号セット名.
-
#operated ⇒ True, False
readonly
運用値.
Instance Method Summary collapse
-
#calc_last_date_on_gengou_data(next_index:, gengou:) ⇒ Gengou
次の元号の開始日から、元号の終了日に変換する.
-
#create ⇒ Type::Base::GengouSet
元号セット情報を生成する.
-
#create_list ⇒ Array<Type::Base::Gengou>
元号情報を生成する.
-
#initialize(hash:, operated: false) ⇒ GengouSetParser
constructor
初期化.
Constructor Details
#initialize(hash:, operated: false) ⇒ GengouSetParser
初期化
91 92 93 94 95 96 97 98 |
# File 'lib/zakuro/era/japan/gengou/resource/parser.rb', line 91 def initialize(hash:, operated: false) @id = hash['id'] @name = hash['name'] @last_year = hash['last_year'] @last_date = hash['last_date'] @list = hash['list'] @operated = operated end |
Instance Attribute Details
#id ⇒ String (readonly)
Returns 元号セットID.
73 74 75 |
# File 'lib/zakuro/era/japan/gengou/resource/parser.rb', line 73 def id @id end |
#last_date ⇒ Hash<String, String> (readonly)
Returns 終了日.
79 80 81 |
# File 'lib/zakuro/era/japan/gengou/resource/parser.rb', line 79 def last_date @last_date end |
#last_year ⇒ Hash<String, String> (readonly)
Returns 終了年.
77 78 79 |
# File 'lib/zakuro/era/japan/gengou/resource/parser.rb', line 77 def last_year @last_year end |
#list ⇒ Array<Hash<String, String>> (readonly)
Returns 元号情報.
81 82 83 |
# File 'lib/zakuro/era/japan/gengou/resource/parser.rb', line 81 def list @list end |
#name ⇒ String (readonly)
Returns 元号セット名.
75 76 77 |
# File 'lib/zakuro/era/japan/gengou/resource/parser.rb', line 75 def name @name end |
#operated ⇒ True, False (readonly)
Returns 運用値.
83 84 85 |
# File 'lib/zakuro/era/japan/gengou/resource/parser.rb', line 83 def operated @operated end |
Instance Method Details
#calc_last_date_on_gengou_data(next_index:, gengou:) ⇒ Gengou
次の元号の開始日から、元号の終了日に変換する
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/zakuro/era/japan/gengou/resource/parser.rb', line 143 def calc_last_date_on_gengou_data(next_index:, gengou:) if next_index >= list.size last_gengou_data(gengou: gengou) return gengou end next_item = list[next_index] next_start_date = SwitchDateParser.new( hash: next_item['start_date'], operated: operated ).create gengou.convert_next_start_year_to_last_year( next_start_year: next_item['start_year']['western'] ) gengou.convert_next_start_date_to_last_date( next_start_date: next_start_date.western ) gengou end |
#create ⇒ Type::Base::GengouSet
元号セット情報を生成する
105 106 107 108 109 110 111 |
# File 'lib/zakuro/era/japan/gengou/resource/parser.rb', line 105 def create date = SwitchDateParser.new(hash: last_date, operated: operated).create list = create_list Type::Base::GengouSet.new( id: id, name: name, last_date: date, list: list ) end |
#create_list ⇒ Array<Type::Base::Gengou>
元号情報を生成する
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/zakuro/era/japan/gengou/resource/parser.rb', line 120 def create_list result = [] list.each_with_index do |li, index| gengou = GengouParser.new( hash: li, index: index, operated: operated ).create next_index = index + 1 gengou = calc_last_date_on_gengou_data(next_index: next_index, gengou: gengou) result.push(gengou) end result end |