Class: Zakuro::Calculation::Monthly::InitializedMonth
- Defined in:
- lib/zakuro/calculation/monthly/initialized_month.rb
Overview
InitializedMonth 初期月情報
Instance Attribute Summary collapse
- #is_last_year ⇒ True, False readonly
-
#phase_index ⇒ Integer
readonly
月齢(朔月、上弦、望月、下弦).
Attributes inherited from Month
#context, #first_day, #gengou, #meta, #month_label, #solar_term_selector
Class Method Summary collapse
-
.month_number_by_even_term_index(index) ⇒ Integer
中気の連番に合わせて月を返す.
-
.month_number_by_odd_term_index(index) ⇒ Integer
節気の連番に合わせて月を返す.
Instance Method Summary collapse
-
#back_to_last_month ⇒ Object
一ヶ月戻す.
-
#initialize(context:, month_label: MonthLabel.new, solar_terms: [], first_day: FirstDay.new, is_last_year: false, phase_index: -1,, meta: Meta.new) ⇒ InitializedMonth
constructor
初期化.
-
#rename_month_label_by_solar_term ⇒ Object
現在の二十四節気に合わせて月表示情報を書き換える.
-
#solar_term_size ⇒ Integer
二十四節気の数を返す.
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
初期化
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: ) @is_last_year = is_last_year @phase_index = phase_index end |
Instance Attribute Details
#is_last_year ⇒ True, False (readonly)
Note:
冬至基準で1年データを作成するため昨年の11月-12月である可能性がある
18 19 20 |
# File 'lib/zakuro/calculation/monthly/initialized_month.rb', line 18 def is_last_year @is_last_year end |
#phase_index ⇒ Integer (readonly)
Returns 月齢(朔月、上弦、望月、下弦).
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
中気の連番に合わせて月を返す
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
節気の連番に合わせて月を返す
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_month ⇒ Object
一ヶ月戻す
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_term ⇒ Object
現在の二十四節気に合わせて月表示情報を書き換える
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_size ⇒ Integer
二十四節気の数を返す
84 85 86 |
# File 'lib/zakuro/calculation/monthly/initialized_month.rb', line 84 def solar_term_size solar_terms.size end |