Class: Zakuro::Calculation::Range::AbstractOperationRange
- Inherits:
-
Object
- Object
- Zakuro::Calculation::Range::AbstractOperationRange
- Defined in:
- lib/zakuro/calculation/range/abstract_operation_range.rb
Overview
AbstractOperationRange 運用結果範囲
何らかの理由により、計算された暦とは異なる運用結果である場合、その結果に合わせて計算結果を上書きする
Direct Known Subclasses
Instance Attribute Summary collapse
-
#context ⇒ Context::Context
readonly
暦コンテキスト.
-
#operated_solar_term ⇒ OperatedSolarTerm
readonly
運用時二十四節気.
-
#years ⇒ Array<Year>
readonly
年データ(完全範囲).
Class Method Summary collapse
-
.commit(operated_years:) ⇒ Object
年を確定させる.
-
.move(operated_years:) ⇒ Object
運用情報で年を跨ぐ月をその年に寄せる.
-
.move_into_last_year(operated_years:) ⇒ Object
運用情報では昨年に属する月を昨年に寄せる.
-
.move_into_next_year(operated_years:) ⇒ Object
運用情報では来年に属する月を来年に寄せる.
-
.reset_meta(years: []) ⇒ Object
メタ情報を更新する.
-
.resolve_month(context:, month:, operated_solar_term:) ⇒ Month
履歴情報の有無に応じた月にする.
-
.rewrite_month(context:, month:, history:, operated_solar_term:) ⇒ Monthly::Month
月を運用結果に書き換える.
-
.rewrite_year(year:, operated_solar_term:) ⇒ OperatedYear
年を書き換える.
Instance Method Summary collapse
-
#get ⇒ Array<Year>
運用結果範囲を取得する.
-
#initialize(context:, scroll:, years: []) ⇒ AbstractOperationRange
constructor
初期化.
-
#rewrite ⇒ Array<OperatedYear>
運用結果に書き換える.
Constructor Details
#initialize(context:, scroll:, years: []) ⇒ AbstractOperationRange
初期化
34 35 36 37 38 39 40 |
# File 'lib/zakuro/calculation/range/abstract_operation_range.rb', line 34 def initialize(context:, scroll:, years: []) @context = context @years = years @scroll = scroll @operated_solar_term = OperatedSolarTerm.new(context: context, years: @years) operated_solar_term.create end |
Instance Attribute Details
#context ⇒ Context::Context (readonly)
Returns 暦コンテキスト.
25 26 27 |
# File 'lib/zakuro/calculation/range/abstract_operation_range.rb', line 25 def context @context end |
#operated_solar_term ⇒ OperatedSolarTerm (readonly)
Returns 運用時二十四節気.
23 24 25 |
# File 'lib/zakuro/calculation/range/abstract_operation_range.rb', line 23 def operated_solar_term @operated_solar_term end |
#years ⇒ Array<Year> (readonly)
Returns 年データ(完全範囲).
21 22 23 |
# File 'lib/zakuro/calculation/range/abstract_operation_range.rb', line 21 def years @years end |
Class Method Details
.commit(operated_years:) ⇒ Object
年を確定させる
124 125 126 |
# File 'lib/zakuro/calculation/range/abstract_operation_range.rb', line 124 def commit(operated_years:) operated_years.each(&:commit) end |
.move(operated_years:) ⇒ Object
運用情報で年を跨ぐ月をその年に寄せる
86 87 88 89 |
# File 'lib/zakuro/calculation/range/abstract_operation_range.rb', line 86 def move(operated_years:) move_into_next_year(operated_years: operated_years) move_into_last_year(operated_years: operated_years) end |
.move_into_last_year(operated_years:) ⇒ Object
運用情報では昨年に属する月を昨年に寄せる
109 110 111 112 113 114 115 116 117 |
# File 'lib/zakuro/calculation/range/abstract_operation_range.rb', line 109 def move_into_last_year(operated_years:) rerversed_year = operated_years.reverse! rerversed_year.each_cons(2) do |current_year, last_year| months = current_year.shift_last_year_months last_year.push_months(months) end rerversed_year.reverse! end |
.move_into_next_year(operated_years:) ⇒ Object
運用情報では来年に属する月を来年に寄せる
96 97 98 99 100 101 102 |
# File 'lib/zakuro/calculation/range/abstract_operation_range.rb', line 96 def move_into_next_year(operated_years:) operated_years.each_cons(2) do |current_year, next_year| months = current_year.pop_next_year_months next_year.unshift_months(months) end end |
.reset_meta(years: []) ⇒ Object
メタ情報を更新する
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/zakuro/calculation/range/abstract_operation_range.rb', line 197 def (years: []) months = [] years.each do |year| months |= year.months end months.each_cons(2) do |last, current| current.(last: last) end end |
.resolve_month(context:, month:, operated_solar_term:) ⇒ Month
履歴情報の有無に応じた月にする
158 159 160 161 162 163 164 165 |
# File 'lib/zakuro/calculation/range/abstract_operation_range.rb', line 158 def resolve_month(context:, month:, operated_solar_term:) history = Operation.specify_history(western_date: month.western_date) rewrite_month( context: context, month: month, history: history, operated_solar_term: operated_solar_term ) end |
.rewrite_month(context:, month:, history:, operated_solar_term:) ⇒ Monthly::Month
月を運用結果に書き換える
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/zakuro/calculation/range/abstract_operation_range.rb', line 179 def rewrite_month(context:, month:, history:, operated_solar_term:) operated_month = Monthly::OperatedMonth.new( context: context, month_label: month.month_label, first_day: month.first_day, solar_terms: month.solar_terms, history: history, gengou: month.gengou, operated_solar_term: operated_solar_term, meta: month. ) operated_month.rewrite unless history.invalid? operated_month end |
.rewrite_year(year:, operated_solar_term:) ⇒ OperatedYear
年を書き換える
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/zakuro/calculation/range/abstract_operation_range.rb', line 136 def rewrite_year(year:, operated_solar_term:) context = year.context result = Base::OperatedYear.new(context: context) year.months.each do |month| result.push(month: resolve_month( context: context, month: month, operated_solar_term: operated_solar_term )) end result end |
Instance Method Details
#get ⇒ Array<Year>
運用結果範囲を取得する
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/zakuro/calculation/range/abstract_operation_range.rb', line 47 def get operated_years = rewrite self.class.move(operated_years: operated_years) self.class.commit(operated_years: operated_years) Transfer::GengouScroller.set(scroll: @scroll, years: operated_years) self.class.(years: operated_years) operated_years end |
#rewrite ⇒ Array<OperatedYear>
運用結果に書き換える
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/zakuro/calculation/range/abstract_operation_range.rb', line 66 def rewrite operated_years = [] years.each do |year| operated_year = self.class.rewrite_year( year: year, operated_solar_term: operated_solar_term ) operated_years.push(operated_year) end operated_years end |