Class: Zakuro::Calculation::Base::OperatedYear
- Defined in:
- lib/zakuro/calculation/base/operated_year.rb
Overview
OperatedYear 年(運用)
Instance Attribute Summary
Attributes inherited from Year
#context, #months, #total_days
Class Method Summary collapse
-
.devide_with(method:, arr: []) ⇒ Array<Object>
メソッドで配列を分離する.
Instance Method Summary collapse
-
#initialize(context: Context::Context.new, months: [], total_days: 0) ⇒ OperatedYear
constructor
初期化.
-
#pop_next_year_months ⇒ Array<OperatedMonth>
来年に属する月を取り出す.
-
#push_months(last_months) ⇒ Object
引数を月の最後に加える.
-
#shift_last_year_months ⇒ Array<OperatedMonth>
昨年に属する月を取り出す.
-
#unshift_months(first_months) ⇒ Object
引数を月の先頭に加える.
Methods inherited from Year
#commit, #duplicated?, #new_year_date, #next_year, #push, #zodiac_name
Constructor Details
#initialize(context: Context::Context.new, months: [], total_days: 0) ⇒ OperatedYear
初期化
24 25 26 |
# File 'lib/zakuro/calculation/base/operated_year.rb', line 24 def initialize(context: Context::Context.new, months: [], total_days: 0) super(context: context, months: months, total_days: total_days) end |
Class Method Details
.devide_with(method:, arr: []) ⇒ Array<Object>
メソッドで配列を分離する
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/zakuro/calculation/base/operated_year.rb', line 87 def devide_with(method:, arr: []) match = [] unmatch = [] arr.each do |item| if !item.moved? && item.send(method) match.push(item) next end unmatch.push(item) end [match, unmatch] end |
Instance Method Details
#pop_next_year_months ⇒ Array<OperatedMonth>
来年に属する月を取り出す
69 70 71 72 73 |
# File 'lib/zakuro/calculation/base/operated_year.rb', line 69 def pop_next_year_months result, @months = self.class.devide_with(method: :next_year?, arr: months) result end |
#push_months(last_months) ⇒ Object
引数を月の最後に加える
46 47 48 49 50 51 |
# File 'lib/zakuro/calculation/base/operated_year.rb', line 46 def push_months(last_months) last_months.each do |month| month.moved months.push(month) end end |
#shift_last_year_months ⇒ Array<OperatedMonth>
昨年に属する月を取り出す
58 59 60 61 62 |
# File 'lib/zakuro/calculation/base/operated_year.rb', line 58 def shift_last_year_months result, @months = self.class.devide_with(method: :last_year?, arr: months) result end |
#unshift_months(first_months) ⇒ Object
引数を月の先頭に加える
33 34 35 36 37 38 39 |
# File 'lib/zakuro/calculation/base/operated_year.rb', line 33 def unshift_months(first_months) # 逆順で加える first_months.reverse_each do |month| month.moved months.unshift(month) end end |