class Zakuro::Calculation::Base::Year

Year

Attributes

months[R]

@return [Array<Month>] 年内の全ての月

multi_gengou[R]

@return [Gengou] 元号

new_year_date[R]

@return [Western::Calendar] 元旦

total_days[R]

@return [Integer] 年の日数

Public Class Methods

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<Month>] months 年内の全ての月 @param [Integer] total_days 年の日数 @param [Western::Calendar] new_year_date 元旦

# File lib/zakuro/calculation/base/year.rb, line 32
def initialize(multi_gengou: MultiGengou.new, new_year_date: Western::Calendar.new,
               months: [], total_days: 0)
  @multi_gengou = multi_gengou
  @months = months
  @new_year_date = new_year_date
  @total_days = total_days
end

Public Instance Methods

commit() click to toggle source

年の日数を確定する

# File lib/zakuro/calculation/base/year.rb, line 43
def commit
  @total_days = 0
  months.each do |month|
    @total_days += month.days
  end

  self
end
duplicated?(month:) click to toggle source

すでに登録済みの月と重複しているか判定する

@note 昨年11月1日から今年1月1日の前日までで、去年データと重複する場合は登録スキップする

@param [Month] month 月

@return [True] 重複している @return [True] 重複していない

# File lib/zakuro/calculation/base/year.rb, line 101
def duplicated?(month:)
  @months.each do |existed|
    return true if existed.same?(other: month)
  end
  false
end
next_year() click to toggle source

次年にする

@param [Japan::Gengou] first_line 元号(1行目) @param [Japan::Gengou] second_line 元号(2行目)

@return [MultiGengou] 自身

# File lib/zakuro/calculation/base/year.rb, line 60
def next_year
  @multi_gengou.next_year

  @new_year_date += @total_days
  @total_days = 0

  self
end
push(month:) click to toggle source

月を追加する

@param [Month] month 月

# File lib/zakuro/calculation/base/year.rb, line 83
def push(month:)
  return if duplicated?(month: month)

  @months.push(month)

  nil
end
zodiac_name() click to toggle source

十干十二支を取得する

@return [String] 十干十二支

# File lib/zakuro/calculation/base/year.rb, line 74
def zodiac_name
  Cycle::Zodiac.year_name(western_year: @new_year_date.year)
end