Class: Zakuro::Calculation::Monthly::SolarTermSelector
- Inherits:
-
Object
- Object
- Zakuro::Calculation::Monthly::SolarTermSelector
- Defined in:
- lib/zakuro/calculation/monthly/internal/solar_term_selector.rb
Overview
SolarTermSelector 二十四節気検索
Constant Summary collapse
- LAST_DAY_LIMIT =
Returns 月最後の二十四節気を検索する大余の範囲上限.
20
Instance Attribute Summary collapse
-
#context ⇒ Context::Context
readonly
暦コンテキスト.
-
#solar_terms ⇒ Array<Cyle::AbstractSolarTerm>
readonly
二十四節気.
Instance Method Summary collapse
-
#add_term(term:) ⇒ Object
二十四節気を追加する.
-
#empty? ⇒ True, False
二十四節気が未設定かどうかを検証する.
-
#even_term ⇒ Cycle::AbstractSolarTerm
中気を返す.
-
#initialize(context: Context::Context.new, solar_terms: []) ⇒ SolarTermSelector
constructor
初期化.
-
#odd_term ⇒ Cycle::AbstractSolarTerm
節気を返す.
-
#solar_term_by_day(day:, meta:) ⇒ Cycle::AbstractSolarTerm
大余に対応する二十四節気.
-
#sort ⇒ Object
二十四節気を正しい順序にソートする.
Constructor Details
#initialize(context: Context::Context.new, solar_terms: []) ⇒ SolarTermSelector
初期化
29 30 31 32 |
# File 'lib/zakuro/calculation/monthly/internal/solar_term_selector.rb', line 29 def initialize(context: Context::Context.new, solar_terms: []) @context = context @solar_terms = solar_terms end |
Instance Attribute Details
#context ⇒ Context::Context (readonly)
Returns 暦コンテキスト.
19 20 21 |
# File 'lib/zakuro/calculation/monthly/internal/solar_term_selector.rb', line 19 def context @context end |
#solar_terms ⇒ Array<Cyle::AbstractSolarTerm> (readonly)
Returns 二十四節気.
21 22 23 |
# File 'lib/zakuro/calculation/monthly/internal/solar_term_selector.rb', line 21 def solar_terms @solar_terms end |
Instance Method Details
#add_term(term:) ⇒ Object
二十四節気を追加する
75 76 77 |
# File 'lib/zakuro/calculation/monthly/internal/solar_term_selector.rb', line 75 def add_term(term:) solar_terms.push(term) end |
#empty? ⇒ True, False
二十四節気が未設定かどうかを検証する
40 41 42 |
# File 'lib/zakuro/calculation/monthly/internal/solar_term_selector.rb', line 40 def empty? solar_terms.empty? end |
#even_term ⇒ Cycle::AbstractSolarTerm
中気を返す
49 50 51 52 53 54 55 |
# File 'lib/zakuro/calculation/monthly/internal/solar_term_selector.rb', line 49 def even_term solar_terms.each do |term| return term if term.index.even? end context.resolver.solar_term.new end |
#odd_term ⇒ Cycle::AbstractSolarTerm
節気を返す
62 63 64 65 66 67 68 |
# File 'lib/zakuro/calculation/monthly/internal/solar_term_selector.rb', line 62 def odd_term solar_terms.each do |term| return term if term.index.odd? end context.resolver.solar_term.new end |
#solar_term_by_day(day:, meta:) ⇒ Cycle::AbstractSolarTerm
大余に対応する二十四節気
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/zakuro/calculation/monthly/internal/solar_term_selector.rb', line 111 def solar_term_by_day(day:, meta:) target = context.resolver.remainder.new(day: day, minute: 0, second: 0) .all_solar_terms.each_cons(2) do |current_solar_term, next_solar_term| in_range = Tool::RemainderComparer.in_range?( target: target, start: current_solar_term.remainder, last: next_solar_term.remainder ) return current_solar_term if in_range end last_solar_term(target: target, meta: ) end |
#sort ⇒ Object
二十四節気を正しい順序にソートする
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/zakuro/calculation/monthly/internal/solar_term_selector.rb', line 82 def sort sorted = (solar_terms.sort do |termx, termy| termx.index <=> termy.index end) unless reset_term?(solar_terms: sorted) @solar_terms = sorted return end @solar_terms = reset(terms: sorted) end |