Class: Zakuro::Calculation::Gengou::Counter
- Inherits:
-
Object
- Object
- Zakuro::Calculation::Gengou::Counter
- Defined in:
- lib/zakuro/calculation/era/gengou/internal/counter.rb
Overview
Counter 加算元号
Constant Summary collapse
- INVALID_YEAR =
Returns 不正値.
-1
Instance Attribute Summary collapse
-
#gengou ⇒ Japan::Resource::Gengou
readonly
元号.
-
#japan_year ⇒ Integer
readonly
元号年.
-
#last_date ⇒ Western::Calendar
readonly
西暦終了年.
-
#start_date ⇒ Western::Calendar
readonly
西暦開始年.
-
#western_year ⇒ Integer
readonly
西暦年.
Instance Method Summary collapse
-
#change_last_date? ⇒ True, False
終了日が設定された終了日と異なるか(行が変更されているか).
-
#change_start_date? ⇒ True, False
開始日が設定された開始日と異なるか(行が変更されているか).
-
#changed? ⇒ True, False
元は1繋ぎであった元号が別の行に存在するか(設定値から変更されているか)?.
-
#include? ⇒ True, False
指定した日が元号に含まれるか.
-
#initialize(gengou: Japan::Resource::Gengou.new, start_date: Western::Calendar.new, last_date: Western::Calendar.new, japan_year: INVALID_YEAR) ⇒ Counter
constructor
初期化.
-
#initialize_copy(obj) ⇒ Object
ディープコピー.
-
#invalid? ⇒ True, False
不正か.
-
#japan_start_date ⇒ Japan::Calendar
和暦開始日を取得する.
-
#name ⇒ String
元号名を取得する.
-
#next_year ⇒ MultiGengou
次年にする.
-
#western_last_date ⇒ Western::Calendar
西暦終了日を取得する.
-
#western_start_date ⇒ Western::Calendar
西暦開始日を取得する.
Constructor Details
#initialize(gengou: Japan::Resource::Gengou.new, start_date: Western::Calendar.new, last_date: Western::Calendar.new, japan_year: INVALID_YEAR) ⇒ Counter
初期化
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 39 def initialize(gengou: Japan::Resource::Gengou.new, start_date: Western::Calendar.new, last_date: Western::Calendar.new, japan_year: INVALID_YEAR) @gengou = gengou @japan_year = japan_year @japan_year = gengou.start_year.japan if @japan_year == INVALID_YEAR @western_year = gengou.start_year.western @start_date = start_date.clone @last_date = last_date.clone select_valid_date end |
Instance Attribute Details
#gengou ⇒ Japan::Resource::Gengou (readonly)
Returns 元号.
21 22 23 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 21 def gengou @gengou end |
#japan_year ⇒ Integer (readonly)
Returns 元号年.
23 24 25 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 23 def japan_year @japan_year end |
#last_date ⇒ Western::Calendar (readonly)
Returns 西暦終了年.
29 30 31 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 29 def last_date @last_date end |
#start_date ⇒ Western::Calendar (readonly)
Returns 西暦開始年.
27 28 29 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 27 def start_date @start_date end |
#western_year ⇒ Integer (readonly)
Returns 西暦年.
25 26 27 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 25 def western_year @western_year end |
Instance Method Details
#change_last_date? ⇒ True, False
終了日が設定された終了日と異なるか(行が変更されているか)
163 164 165 166 167 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 163 def change_last_date? return false if invalid? last_date != native_last_date end |
#change_start_date? ⇒ True, False
開始日が設定された開始日と異なるか(行が変更されているか)
151 152 153 154 155 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 151 def change_start_date? return false if invalid? start_date != native_start_date end |
#changed? ⇒ True, False
元は1繋ぎであった元号が別の行に存在するか(設定値から変更されているか)?
137 138 139 140 141 142 143 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 137 def changed? return true if change_start_date? return true if change_last_date? false end |
#include? ⇒ True, False
指定した日が元号に含まれるか
127 128 129 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 127 def include? gengou.include? end |
#initialize_copy(obj) ⇒ Object
ディープコピー
174 175 176 177 178 179 180 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 174 def initialize_copy(obj) @gengou = obj.gengou.clone @japan_year = obj.japan_year @western_year = obj.western_year @start_date = obj.start_date.clone @last_date = obj.last_date.clone end |
#invalid? ⇒ True, False
不正か
115 116 117 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 115 def invalid? gengou.invalid? || japan_year == INVALID_YEAR || western_year == INVALID_YEAR end |
#japan_start_date ⇒ Japan::Calendar
和暦開始日を取得する
58 59 60 61 62 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 58 def japan_start_date return Japan::Calendar.new if gengou.invalid? gengou.start_date.japan end |
#name ⇒ String
元号名を取得する
103 104 105 106 107 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 103 def name return '' unless @gengou gengou.name end |
#next_year ⇒ MultiGengou
次年にする
91 92 93 94 95 96 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 91 def next_year @japan_year += 1 @western_year += 1 self end |
#western_last_date ⇒ Western::Calendar
西暦終了日を取得する
80 81 82 83 84 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 80 def western_last_date return Western::Calendar.new if gengou.invalid? last_date end |
#western_start_date ⇒ Western::Calendar
西暦開始日を取得する
69 70 71 72 73 |
# File 'lib/zakuro/calculation/era/gengou/internal/counter.rb', line 69 def western_start_date return Western::Calendar.new if gengou.invalid? start_date end |