Class: Zakuro::Japan::Type::Base::Gengou
- Inherits:
-
Object
- Object
- Zakuro::Japan::Type::Base::Gengou
- Defined in:
- lib/zakuro/era/japan/type/base/gengou.rb
Overview
Gengou 元号情報
Instance Attribute Summary collapse
-
#last_date ⇒ Western::Calendar
readonly
終了日.
-
#last_year ⇒ Integer
readonly
終了年.
-
#name ⇒ String
readonly
元号名.
-
#start_date ⇒ SwitchDate
readonly
開始日(和暦/西暦).
-
#start_year ⇒ Both::Year
readonly
開始年(和暦/西暦).
Class Method Summary collapse
-
.valid_date(date:) ⇒ True, False
日付が不正なしかどうかを確認する.
-
.valid_year(year:) ⇒ True, False
年が不正なしかどうかを確認する.
Instance Method Summary collapse
-
#convert_next_start_date_to_last_date(next_start_date: Western::Calendar.new) ⇒ Object
次の元号の開始日から、元号の終了日に変換する.
-
#convert_next_start_year_to_last_year(next_start_year:) ⇒ Object
次の元号の開始年から、元号の終了年に変換する.
-
#include?(date:) ⇒ True, False
指定した日が元号に含まれるか.
-
#initialize(name: '', start_year: Both::Year.new, start_date: SwitchDate.new, last_date: Western::Calendar.new, last_year: Both::Year::INVALID) ⇒ Gengou
constructor
初期化.
-
#invalid? ⇒ True, False
不正か.
-
#to_s ⇒ String
インスタンス値(文字列)を取得する.
-
#write_last_date(last_date:) ⇒ Object
終了日を更新する.
-
#write_last_year(last_year:) ⇒ Object
終了年を更新する.
Constructor Details
#initialize(name: '', start_year: Both::Year.new, start_date: SwitchDate.new, last_date: Western::Calendar.new, last_year: Both::Year::INVALID) ⇒ Gengou
初期化
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 38 def initialize(name: '', start_year: Both::Year.new, start_date: SwitchDate.new, last_date: Western::Calendar.new, last_year: Both::Year::INVALID) @name = name @start_year = start_year @start_date = start_date @last_year = last_year @last_date = last_date end |
Instance Attribute Details
#last_date ⇒ Western::Calendar (readonly)
Returns 終了日.
27 28 29 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 27 def last_date @last_date end |
#last_year ⇒ Integer (readonly)
Returns 終了年.
25 26 27 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 25 def last_year @last_year end |
#name ⇒ String (readonly)
Returns 元号名.
19 20 21 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 19 def name @name end |
#start_date ⇒ SwitchDate (readonly)
Returns 開始日(和暦/西暦).
23 24 25 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 23 def start_date @start_date end |
#start_year ⇒ Both::Year (readonly)
Returns 開始年(和暦/西暦).
21 22 23 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 21 def start_year @start_year end |
Class Method Details
.valid_date(date:) ⇒ True, False
日付が不正なしかどうかを確認する
167 168 169 170 171 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 167 def valid_date(date:) return false unless date date.is_a?(Western::Calendar) end |
.valid_year(year:) ⇒ True, False
年が不正なしかどうかを確認する
153 154 155 156 157 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 153 def valid_year(year:) return false unless year year.is_a?(Integer) end |
Instance Method Details
#convert_next_start_date_to_last_date(next_start_date: Western::Calendar.new) ⇒ Object
次の元号の開始日から、元号の終了日に変換する
103 104 105 106 107 108 109 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 103 def convert_next_start_date_to_last_date(next_start_date: Western::Calendar.new) raise ArgumentError, 'invalid value. cannot convert' if next_start_date.invalid? @last_date = next_start_date.clone - 1 nil end |
#convert_next_start_year_to_last_year(next_start_year:) ⇒ Object
次の元号の開始年から、元号の終了年に変換する
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 85 def convert_next_start_year_to_last_year(next_start_year:) if start_year.western >= next_start_year @last_year = next_start_year return end @last_year = next_start_year - 1 nil end |
#include?(date:) ⇒ True, False
指定した日が元号に含まれるか
119 120 121 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 119 def include?(date:) date >= start_date.western && date <= last_date end |
#invalid? ⇒ True, False
不正か
129 130 131 132 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 129 def invalid? start_year.japan == -1 || start_year.invalid? || start_date.invalid? || last_date.invalid? end |
#to_s ⇒ String
インスタンス値(文字列)を取得する
139 140 141 142 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 139 def to_s "name: #{@name}, start_year: #{start_year.format}, " \ "start_date: #{start_date.format}, last_date: #{last_date.format}" end |
#write_last_date(last_date:) ⇒ Object
終了日を更新する
71 72 73 74 75 76 77 78 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 71 def write_last_date(last_date:) unless self.class.valid_date(date: last_date) raise ArgumentError, "invalid date format. [#{last_date}]" end @last_date = last_date nil end |
#write_last_year(last_year:) ⇒ Object
終了年を更新する
56 57 58 59 60 61 62 |
# File 'lib/zakuro/era/japan/type/base/gengou.rb', line 56 def write_last_year(last_year:) unless self.class.valid_year(year: last_year) raise ArgumentError, "invalid year format. [#{last_year}]" end @last_year = last_year end |