class Zakuro::Calculation::Base::OperatedYear
OperatedYear
年(運用)
Public Class Methods
devide_with(method:, arr: [])
click to toggle source
メソッドで配列を分離する
@param [Symbol] method 条件メソッド @param [Array<Object>] arr 配列
@return [Array<Object>] 一致配列 @return [Array<Object>] 不一致配列
# File lib/zakuro/calculation/base/operated_year.rb, line 96 def self.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
new(multi_gengou: MultiGengou.new, new_year_date: Western::Calendar.new, months: [], total_days: 0)
click to toggle source
初期化
@param [Gengou] multi_gengou 元号 @param [Array<OperatedMonth>] months 年内の全ての月 @param [Integer] total_days 年の日数 @param [Western::Calendar] new_year_date 元旦
Calls superclass method
# File lib/zakuro/calculation/base/operated_year.rb, line 24 def initialize(multi_gengou: MultiGengou.new, new_year_date: Western::Calendar.new, months: [], total_days: 0) super(multi_gengou: multi_gengou, new_year_date: new_year_date, months: months, total_days: total_days) end
Public Instance Methods
commit()
click to toggle source
Calls superclass method
# File lib/zakuro/calculation/base/operated_year.rb, line 30 def commit super return if months.empty? @new_year_date = months[0].first_day.western_date end
pop_next_year_months()
click to toggle source
来年に属する月を取り出す
@return [Array<OperatedMonth>] 来年に属する月
# File lib/zakuro/calculation/base/operated_year.rb, line 79 def pop_next_year_months result, @months = OperatedYear.devide_with(method: :next_year?, arr: months) result end
push_months(last_months)
click to toggle source
引数を月の最後に加える
@param [Array<OperatedMonth>] last_months 最後の月
# File lib/zakuro/calculation/base/operated_year.rb, line 56 def push_months(last_months) last_months.each do |month| month.moved months.push(month) end end
shift_last_year_months()
click to toggle source
昨年に属する月を取り出す
@return [Array<OperatedMonth>] 昨年に属する月
# File lib/zakuro/calculation/base/operated_year.rb, line 68 def shift_last_year_months result, @months = OperatedYear.devide_with(method: :last_year?, arr: months) result end
unshift_months(first_months)
click to toggle source
引数を月の先頭に加える
@param [Array<OperatedMonth>] first_months 先頭の月
# File lib/zakuro/calculation/base/operated_year.rb, line 43 def unshift_months(first_months) # 逆順で加える first_months.reverse_each do |month| month.moved months.unshift(month) end end