Class: Zakuro::Calculation::Monthly::InitializedMonth

Inherits:
Month
  • Object
show all
Defined in:
lib/zakuro/calculation/monthly/initialized_month.rb

Overview

InitializedMonth 初期月情報

Instance Attribute Summary collapse

Attributes inherited from Month

#context, #first_day, #gengou, #meta, #month_label, #solar_term_selector

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Month

#add_term, #days, #days_name, #empty_solar_term?, #eval_leaped, #eval_many_days, #even_term, #include?, #include_by_japan_date?, #invalid?, #last_date, #leaped?, #many_days?, #number, #odd_term, #remainder, #reset_meta, #same?, #solar_term_by_day, #solar_terms, #sort_solar_terms, #western_date

Constructor Details

#initialize(context:, month_label: MonthLabel.new, solar_terms: [], first_day: FirstDay.new, is_last_year: false, phase_index: -1,, meta: Meta.new) ⇒ InitializedMonth

初期化

Parameters:

  • context (Context::Context)

    暦コンテキスト

  • month_label (MonthLabel) (defaults to: MonthLabel.new)

    月表示名

  • solar_terms (Array<SolarTerm>) (defaults to: [])

    二十四節気

  • first_day (FirstDay) (defaults to: FirstDay.new)

    月初日(朔日)

  • is_last_year (True, False) (defaults to: false)

    昨年の月/今年の月

  • phase_index (Integer) (defaults to: -1,)

    月齢(朔月、上弦、望月、下弦)

  • meta (Meta) (defaults to: Meta.new)

    付加情報



36
37
38
39
40
41
42
43
# File 'lib/zakuro/calculation/monthly/initialized_month.rb', line 36

def initialize(context:, month_label: MonthLabel.new, solar_terms: [],
               first_day: FirstDay.new, is_last_year: false, phase_index: -1,
               meta: Meta.new)
  super(context: context, month_label: month_label, solar_terms: solar_terms,
        first_day: first_day, meta: meta)
  @is_last_year = is_last_year
  @phase_index = phase_index
end

Instance Attribute Details

#is_last_yearTrue, False (readonly)

Note:

冬至基準で1年データを作成するため昨年の11月-12月である可能性がある

Returns:

  • (True)

    昨年の月

  • (False)

    今年の月



18
19
20
# File 'lib/zakuro/calculation/monthly/initialized_month.rb', line 18

def is_last_year
  @is_last_year
end

#phase_indexInteger (readonly)

Returns 月齢(朔月、上弦、望月、下弦).

Returns:

  • (Integer)

    月齢(朔月、上弦、望月、下弦)



20
21
22
# File 'lib/zakuro/calculation/monthly/initialized_month.rb', line 20

def phase_index
  @phase_index
end

Class Method Details

.month_number_by_even_term_index(index) ⇒ Integer

中気の連番に合わせて月を返す

Examples:

20: 9月
22: 10月
0: 11月
2: 12月
4: 1月

Parameters:

  • index (Integer)

    中気番号

Returns:

  • (Integer)



103
104
105
106
107
108
109
110
111
# File 'lib/zakuro/calculation/monthly/initialized_month.rb', line 103

def month_number_by_even_term_index(index)
  half_index = index / 2

  # 11月、12月
  return half_index + 11 if half_index < 2

  # 1月~10月
  half_index - 1
end

.month_number_by_odd_term_index(index) ⇒ Integer

節気の連番に合わせて月を返す

Parameters:

  • index (Integer)

    節気番号

Returns:

  • (Integer)



120
121
122
123
124
# File 'lib/zakuro/calculation/monthly/initialized_month.rb', line 120

def month_number_by_odd_term_index(index)
  even_index = index - 1

  month_number_by_even_term_index(even_index)
end

Instance Method Details

#back_to_last_monthObject

一ヶ月戻す



75
76
77
# File 'lib/zakuro/calculation/monthly/initialized_month.rb', line 75

def back_to_last_month
  @is_last_year = true if month_label.back_to_last_month
end

#rename_month_label_by_solar_termObject

現在の二十四節気に合わせて月表示情報を書き換える



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/zakuro/calculation/monthly/initialized_month.rb', line 52

def rename_month_label_by_solar_term
  return ArgumentError.new, 'solar term must not be empty.' if empty_solar_term?

  even = even_term

  is_many_days = month_label.is_many_days
  if even.invalid?
    @month_label = MonthLabel.new(
      number: InitializedMonth.month_number_by_odd_term_index(odd_term.index),
      leaped: true, is_many_days: is_many_days
    )
    return
  end

  @month_label = MonthLabel.new(
    number: InitializedMonth.month_number_by_even_term_index(even.index),
    leaped: false, is_many_days: is_many_days
  )
end

#solar_term_sizeInteger

二十四節気の数を返す

Returns:

  • (Integer)

    二十四節気の数



84
85
86
# File 'lib/zakuro/calculation/monthly/initialized_month.rb', line 84

def solar_term_size
  solar_terms.size
end