Class: Zakuro::Calculation::Cycle::AbstractSolarTerm
- Inherits:
-
Object
- Object
- Zakuro::Calculation::Cycle::AbstractSolarTerm
- Defined in:
- lib/zakuro/calculation/cycle/abstract_solar_term.rb
Overview
AbstractSolarTerm 二十四節気
Direct Known Subclasses
Version::Daien::Cycle::SolarTerm, Version::Genka::Cycle::SolarTerm, Version::Gihou::Cycle::SolarTerm, Version::Senmyou::Cycle::SolarTerm
Constant Summary collapse
- ORDER =
Returns 順序.
{ 0 => :touji, 1 => :shoukan, 2 => :daikan, 3 => :risshun, 4 => :usui, 5 => :keichitsu, 6 => :shunbun, 7 => :seimei, 8 => :kokuu, 9 => :rikka, 10 => :shouman, 11 => :boushu, 12 => :geshi, 13 => :shousho, 14 => :taisho, 15 => :risshuu, 16 => :shosho, 17 => :hakuro, 18 => :shuubun, 19 => :kanro, 20 => :soukou, 21 => :rittou, 22 => :shousetsu, 23 => :taisetsu }.freeze
- FIRST_INDEX =
Returns 開始番号.
0- LAST_INDEX =
Returns 終了番号.
23
Instance Attribute Summary collapse
-
#average ⇒ AbstractRemainder
readonly
気策(24分の1年).
-
#index ⇒ Integer
readonly
連番.
-
#remainder ⇒ AbstractRemainder
readonly
時刻情報(大余小余).
Class Method Summary collapse
-
.index?(index) ⇒ True, False
有効な二十四節気番号か.
Instance Method Summary collapse
-
#empty? ⇒ True, False
データなしかを検証する.
-
#initialize(index: -1,, remainder: AbstractRemainder.new, average: AbstractRemainder.new) ⇒ AbstractSolarTerm
constructor
初期化.
-
#initialize_copy(obj) ⇒ Object
ディープコピー.
-
#invalid? ⇒ True, False
不正かどうか検証する.
-
#next_by_index(index) ⇒ Object
指定した連番の二十四節気まで進める.
-
#next_term ⇒ Object
次の二十四節気に進める.
-
#next_term! ⇒ Object
次の二十四節気に進める.
-
#prev_by_index(index) ⇒ Object
指定した連番の二十四節気まで戻す.
-
#prev_term ⇒ Object
前の二十四節気に戻る.
-
#prev_term! ⇒ Object
前の二十四節気に戻る.
Constructor Details
#initialize(index: -1,, remainder: AbstractRemainder.new, average: AbstractRemainder.new) ⇒ AbstractSolarTerm
初期化
62 63 64 65 66 67 |
# File 'lib/zakuro/calculation/cycle/abstract_solar_term.rb', line 62 def initialize(index: -1, remainder: AbstractRemainder.new, average: AbstractRemainder.new) @index = index @remainder = remainder @average = average end |
Instance Attribute Details
#average ⇒ AbstractRemainder (readonly)
Returns 気策(24分の1年).
20 21 22 |
# File 'lib/zakuro/calculation/cycle/abstract_solar_term.rb', line 20 def average @average end |
#index ⇒ Integer (readonly)
Returns 連番.
16 17 18 |
# File 'lib/zakuro/calculation/cycle/abstract_solar_term.rb', line 16 def index @index end |
#remainder ⇒ AbstractRemainder (readonly)
Returns 時刻情報(大余小余).
18 19 20 |
# File 'lib/zakuro/calculation/cycle/abstract_solar_term.rb', line 18 def remainder @remainder end |
Class Method Details
.index?(index) ⇒ True, False
有効な二十四節気番号か
174 175 176 177 178 |
# File 'lib/zakuro/calculation/cycle/abstract_solar_term.rb', line 174 def index?(index) result = ORDER.fetch(index, -1) result != -1 end |
Instance Method Details
#empty? ⇒ True, False
データなしかを検証する
85 86 87 |
# File 'lib/zakuro/calculation/cycle/abstract_solar_term.rb', line 85 def empty? (index == -1 && remainder.invalid?) end |
#initialize_copy(obj) ⇒ Object
ディープコピー
160 161 162 163 |
# File 'lib/zakuro/calculation/cycle/abstract_solar_term.rb', line 160 def initialize_copy(obj) @index = obj.index.clone @remainder = obj.remainder.clone end |
#invalid? ⇒ True, False
不正かどうか検証する
75 76 77 |
# File 'lib/zakuro/calculation/cycle/abstract_solar_term.rb', line 75 def invalid? (index == -1 || remainder.invalid?) end |
#next_by_index(index) ⇒ Object
指定した連番の二十四節気まで進める
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/zakuro/calculation/cycle/abstract_solar_term.rb', line 111 def next_by_index(index) return ArgumentError.new, 'invalid index' unless AbstractSolarTerm.index?(index) (0..(ORDER.size - 1)).each do |_index| inner_index = @index break if inner_index == index next! end end |
#next_term ⇒ Object
次の二十四節気に進める
99 100 101 102 103 104 |
# File 'lib/zakuro/calculation/cycle/abstract_solar_term.rb', line 99 def next_term @index += 1 @index = 0 if index >= ORDER.size remainder.add(average) end |
#next_term! ⇒ Object
次の二十四節気に進める
92 93 94 |
# File 'lib/zakuro/calculation/cycle/abstract_solar_term.rb', line 92 def next_term! @remainder = next_term end |
#prev_by_index(index) ⇒ Object
指定した連番の二十四節気まで戻す
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/zakuro/calculation/cycle/abstract_solar_term.rb', line 127 def prev_by_index(index) return ArgumentError.new, 'invalid index' unless AbstractSolarTerm.index?(index) (0..(ORDER.size - 1)).each do |_index| inner_index = @index break if inner_index == index prev_term! end end |
#prev_term ⇒ Object
前の二十四節気に戻る
148 149 150 151 152 153 |
# File 'lib/zakuro/calculation/cycle/abstract_solar_term.rb', line 148 def prev_term @index -= 1 @index = ORDER.size - 1 if index.negative? remainder.sub(average) end |
#prev_term! ⇒ Object
前の二十四節気に戻る
141 142 143 |
# File 'lib/zakuro/calculation/cycle/abstract_solar_term.rb', line 141 def prev_term! @remainder = prev_term end |