Class: Zakuro::Calculation::Monthly::Month

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

Overview

Month 月情報

Direct Known Subclasses

InitializedMonth, OperatedMonth

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context: Context::Context.new, month_label: MonthLabel.new, first_day: FirstDay.new, solar_terms: [], gengou: Base::Gengou.new, meta: Meta.new) ⇒ Month

初期化

Parameters:

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

    暦コンテキスト

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

    月表示名

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

    月初日(朔日)

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

    二十四節気

  • gengou (Base::Gengou) (defaults to: Base::Gengou.new)

    元号

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

    付加情報



49
50
51
52
53
54
55
56
57
58
# File 'lib/zakuro/calculation/monthly/month.rb', line 49

def initialize(context: Context::Context.new, month_label: MonthLabel.new,
               first_day: FirstDay.new, solar_terms: [], gengou: Base::Gengou.new,
               meta: Meta.new)
  @context = context
  @month_label = month_label
  @first_day = first_day
  @solar_term_selector = SolarTermSelector.new(context: context, solar_terms: solar_terms)
  @gengou = gengou
  @meta = meta
end

Instance Attribute Details

#contextContext::Context (readonly)

Returns 暦コンテキスト.

Returns:



25
26
27
# File 'lib/zakuro/calculation/monthly/month.rb', line 25

def context
  @context
end

#first_dayFirstDay (readonly)

Returns 月初日(朔日).

Returns:



29
30
31
# File 'lib/zakuro/calculation/monthly/month.rb', line 29

def first_day
  @first_day
end

#gengouBase::Gengou (readonly)

Returns 元号.

Returns:



33
34
35
# File 'lib/zakuro/calculation/monthly/month.rb', line 33

def gengou
  @gengou
end

#metaMeta (readonly)

Returns 付加情報.

Returns:

  • (Meta)

    付加情報



35
36
37
# File 'lib/zakuro/calculation/monthly/month.rb', line 35

def meta
  @meta
end

#month_labelMonthLabel (readonly)

Returns 月表示名.

Returns:



27
28
29
# File 'lib/zakuro/calculation/monthly/month.rb', line 27

def month_label
  @month_label
end

#solar_term_selectorSolarTermSelector (readonly)

Returns 二十四節気検索.

Returns:



31
32
33
# File 'lib/zakuro/calculation/monthly/month.rb', line 31

def solar_term_selector
  @solar_term_selector
end

Instance Method Details

#add_term(term:) ⇒ Object

二十四節気を追加する

Parameters:

  • term (SolarTerm)

    二十四節気



201
202
203
# File 'lib/zakuro/calculation/monthly/month.rb', line 201

def add_term(term:)
  solar_term_selector.add_term(term: term)
end

#daysInteger

月の日数を返す

Returns:

  • (Integer)

    日数



114
115
116
# File 'lib/zakuro/calculation/monthly/month.rb', line 114

def days
  month_label.days
end

#days_nameString

月の名前(大小)を返す

Returns:

  • (String)

    月の名前(大小)



123
124
125
# File 'lib/zakuro/calculation/monthly/month.rb', line 123

def days_name
  month_label.days_name
end

#empty_solar_term?True, False

二十四節気が未設定かどうかを検証する

Returns:

  • (True)

    設定なし

  • (False)

    設定あり



165
166
167
# File 'lib/zakuro/calculation/monthly/month.rb', line 165

def empty_solar_term?
  solar_term_selector.empty?
end

#eval_leapedObject

中気なしは閏月とする



75
76
77
78
79
# File 'lib/zakuro/calculation/monthly/month.rb', line 75

def eval_leaped
  leaped = even_term.invalid?

  @month_label = MonthLabel.new(number: number, is_many_days: many_days?, leaped: leaped)
end

#eval_many_days(next_month_day:) ⇒ Object

次月の大余から月の日数を定める

Parameters:

  • next_month_day (Integer)

    次月の大余



151
152
153
154
155
156
157
# File 'lib/zakuro/calculation/monthly/month.rb', line 151

def eval_many_days(next_month_day:)
  is_many_days = remainder.same_remainder_divided_by_ten?(other: next_month_day)

  @month_label = MonthLabel.new(
    number: number, is_many_days: is_many_days, leaped: leaped?
  )
end

#even_termCycle::AbstractSolarTerm

中気を返す

Returns:



174
175
176
# File 'lib/zakuro/calculation/monthly/month.rb', line 174

def even_term
  solar_term_selector.even_term
end

#include?(date:) ⇒ True, False

範囲内か

Parameters:

Returns:

  • (True)

    範囲内

  • (False)

    範囲外



236
237
238
239
240
241
242
# File 'lib/zakuro/calculation/monthly/month.rb', line 236

def include?(date:)
  return false if invalid?

  DateComparer.include?(
    date: date, start_date: western_date, last_date: last_date
  )
end

#include_by_japan_date?(date:) ⇒ True, False

範囲内か

Parameters:

Returns:

  • (True)

    範囲内

  • (False)

    範囲外



252
253
254
255
256
257
258
# File 'lib/zakuro/calculation/monthly/month.rb', line 252

def include_by_japan_date?(date:)
  return false if invalid?

  DateComparer.include_by_japan_date?(
    date: date, gengou: gengou, month_label: month_label
  )
end

#invalid?True, False

不正か

Returns:

  • (True)

    不正

  • (False)

    不正なし



68
69
70
# File 'lib/zakuro/calculation/monthly/month.rb', line 68

def invalid?
  context.invalid?
end

#last_dateWestern::Calendar

月の終了日を返す

Returns:



222
223
224
225
226
# File 'lib/zakuro/calculation/monthly/month.rb', line 222

def last_date
  return Western::Calendar.new if western_date.invalid?

  western_date.clone + days - 1
end

#leaped?True, False

閏を返す

Returns:

  • (True)

    閏月

  • (False)

    平月



142
143
144
# File 'lib/zakuro/calculation/monthly/month.rb', line 142

def leaped?
  month_label.leaped
end

#many_days?True, False

月の大小を返す

Returns:

  • (True)

    大の月(30日)

  • (False)

    小の月(29日)



105
106
107
# File 'lib/zakuro/calculation/monthly/month.rb', line 105

def many_days?
  month_label.is_many_days
end

#numberInteger

月を返す

Returns:

  • (Integer)

    月(xx月のxx)



132
133
134
# File 'lib/zakuro/calculation/monthly/month.rb', line 132

def number
  month_label.number
end

#odd_termCycle::AbstractSolarTerm

節気を返す

Returns:



183
184
185
# File 'lib/zakuro/calculation/monthly/month.rb', line 183

def odd_term
  solar_term_selector.odd_term
end

#remainderRemainder

月初日の大余小余を返す

Returns:

  • (Remainder)

    大余小余



95
96
97
# File 'lib/zakuro/calculation/monthly/month.rb', line 95

def remainder
  first_day.remainder
end

#reset_meta(last: Month.new) ⇒ Object

メタ情報を再設定する

Parameters:

  • last (Month) (defaults to: Month.new)

    前月



283
284
285
286
287
288
# File 'lib/zakuro/calculation/monthly/month.rb', line 283

def reset_meta(last: Month.new)
  @meta = MetaCollector.get(
    before_month: last,
    current_month: self
  )
end

#same?(other:) ⇒ True, False

同一の月情報かを検証する

Parameters:

  • other (Month)

    他の月情報

Returns:

  • (True)

    同一の月

  • (False)

    異なる月



213
214
215
# File 'lib/zakuro/calculation/monthly/month.rb', line 213

def same?(other:)
  number == other.number && leaped? == other.leaped?
end

#solar_term_by_day(day:) ⇒ Cycle::AbstractSolarTerm

大余に対応する二十四節気

Parameters:

  • day (Integer)

    大余

Returns:



274
275
276
# File 'lib/zakuro/calculation/monthly/month.rb', line 274

def solar_term_by_day(day:)
  solar_term_selector.solar_term_by_day(day: day, meta: meta)
end

#solar_termsArray<Cyle::AbstractSolarTerm>

二十四節気を返す

Returns:

  • (Array<Cyle::AbstractSolarTerm>)

    二十四節気



192
193
194
# File 'lib/zakuro/calculation/monthly/month.rb', line 192

def solar_terms
  solar_term_selector.solar_terms
end

#sort_solar_termsObject

二十四節気を正しい順序にソートする



263
264
265
# File 'lib/zakuro/calculation/monthly/month.rb', line 263

def sort_solar_terms
  solar_term_selector.sort
end

#western_dateWestern::Calendar

月初日の西暦日を返す

Returns:



86
87
88
# File 'lib/zakuro/calculation/monthly/month.rb', line 86

def western_date
  first_day.western_date
end