Class: Zakuro::Calculation::Gengou::Connector
- Inherits:
-
Object
- Object
- Zakuro::Calculation::Gengou::Connector
- Defined in:
- lib/zakuro/calculation/era/gengou/internal/connector.rb
Overview
Connector 元号接続器
現在は“明徳”のみを解決している
元中1年4月28日 元中9年閏10月4日 明徳5年7月4日
1384-05-18 1392-11-18 1394-8-1
[1] |-------------元中---------------|---------明徳------------|
[2] |---------明徳--------|
明徳1年3月26日
1390-04-12
* 明徳は2行目元号から始まる
* 1392-11-19より1行目元号に移行する
* 移行のタイミングで元号年を引き継げるようにする
Instance Attribute Summary collapse
-
#unsolved_list ⇒ Array<Counter>
readonly
未解決元号.
Instance Method Summary collapse
-
#initialize ⇒ Connector
constructor
初期化.
-
#recreate(gengou:, unsolved:) ⇒ Counter
年を更新した元号を生成する.
-
#replace(gengou:) ⇒ Counter
元号を年を更新した元号に入れ替える.
-
#update(lines: []) ⇒ Object
元号を更新する.
Constructor Details
#initialize ⇒ Connector
初期化
35 36 37 |
# File 'lib/zakuro/calculation/era/gengou/internal/connector.rb', line 35 def initialize @unsolved_list = [] end |
Instance Attribute Details
#unsolved_list ⇒ Array<Counter> (readonly)
Returns 未解決元号.
30 31 32 |
# File 'lib/zakuro/calculation/era/gengou/internal/connector.rb', line 30 def unsolved_list @unsolved_list end |
Instance Method Details
#recreate(gengou:, unsolved:) ⇒ Counter
年を更新した元号を生成する
95 96 97 98 99 100 101 102 103 |
# File 'lib/zakuro/calculation/era/gengou/internal/connector.rb', line 95 def recreate(gengou:, unsolved:) japan_year = gengou.japan_year japan_year = unsolved.japan_year if unsolved.japan_year > gengou.japan_year Counter.new( gengou: gengou.gengou, start_date: gengou.start_date, last_date: gengou.last_date, japan_year: japan_year ) end |
#replace(gengou:) ⇒ Counter
元号を年を更新した元号に入れ替える
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/zakuro/calculation/era/gengou/internal/connector.rb', line 61 def replace(gengou:) matched_index = -1 unsolved_list.each_with_index do |unsolved, index| next unless unsolved.name == gengou.name matched_index = index break end if matched_index == -1 unsolved_list.push(gengou) return gengou end matched = unsolved_list[matched_index] result = recreate(gengou: gengou, unsolved: matched) @unsolved_list[matched_index] = result # 分離した元号の末尾まで到達した unsolved_list.delete_at(matched_index) unless result.change_last_date? result end |
#update(lines: []) ⇒ Object
元号を更新する
44 45 46 47 48 49 50 51 52 |
# File 'lib/zakuro/calculation/era/gengou/internal/connector.rb', line 44 def update(lines: []) lines.each do |line| line.each_with_index do |gengou, index| next unless gengou.changed? line[index] = replace(gengou: gengou) end end end |