Class: Zakuro::Calculation::Base::OperatedYear

Inherits:
Year
  • Object
show all
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

Instance Method Summary collapse

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

初期化

Parameters:

  • context (Context::Context) (defaults to: Context::Context.new)

    暦コンテキスト

  • months (Array<OperatedMonth>) (defaults to: [])

    年内の全ての月

  • total_days (Integer) (defaults to: 0)

    年の日数



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>

メソッドで配列を分離する

Parameters:

  • method (Symbol)

    条件メソッド

  • arr (Array<Object>) (defaults to: [])

    配列

Returns:

  • (Array<Object>)

    一致配列

  • (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_monthsArray<OperatedMonth>

来年に属する月を取り出す

Returns:

  • (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

引数を月の最後に加える

Parameters:

  • last_months (Array<OperatedMonth>)

    最後の月



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_monthsArray<OperatedMonth>

昨年に属する月を取り出す

Returns:

  • (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

引数を月の先頭に加える

Parameters:

  • first_months (Array<OperatedMonth>)

    先頭の月



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