Class: Warekky::Era
- Inherits:
-
Object
- Object
- Warekky::Era
- Defined in:
- lib/warekky/era.rb
Instance Attribute Summary collapse
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#sign ⇒ Object
readonly
Returns the value of attribute sign.
Instance Method Summary collapse
- #[](option_key) ⇒ Object
-
#initialize(key, sign, first, last, options = {}) ⇒ Era
constructor
A new instance of Era.
- #match?(d) ⇒ Boolean
- #name ⇒ Object
- #to_ad_year(era_year) ⇒ Object
- #to_era_year(ad_year) ⇒ Object
Constructor Details
#initialize(key, sign, first, last, options = {}) ⇒ Era
6 7 8 9 10 |
# File 'lib/warekky/era.rb', line 6 def initialize(key, sign, first, last, = {}) @key, @sign = key.to_sym, sign.to_s.freeze @first, @last = to_date(first), to_date(last) = ( || {}).freeze end |
Instance Attribute Details
#first ⇒ Object (readonly)
Returns the value of attribute first.
5 6 7 |
# File 'lib/warekky/era.rb', line 5 def first @first end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/warekky/era.rb', line 5 def key @key end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
5 6 7 |
# File 'lib/warekky/era.rb', line 5 def last @last end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/warekky/era.rb', line 5 def end |
#sign ⇒ Object (readonly)
Returns the value of attribute sign.
5 6 7 |
# File 'lib/warekky/era.rb', line 5 def sign @sign end |
Instance Method Details
#[](option_key) ⇒ Object
21 22 23 |
# File 'lib/warekky/era.rb', line 21 def [](option_key) [option_key] end |
#match?(d) ⇒ Boolean
16 17 18 19 |
# File 'lib/warekky/era.rb', line 16 def match?(d) d = to_date(d) (@first ? @first <= d : true) && (@last ? @last >= d : true) end |
#name ⇒ Object
12 13 14 |
# File 'lib/warekky/era.rb', line 12 def name key.to_s end |
#to_ad_year(era_year) ⇒ Object
25 26 27 28 |
# File 'lib/warekky/era.rb', line 25 def to_ad_year(era_year) era_year = era_year.to_i @first.year - 1 + era_year end |
#to_era_year(ad_year) ⇒ Object
30 31 32 33 |
# File 'lib/warekky/era.rb', line 30 def to_era_year(ad_year) ad_year = ad_year.to_i ad_year - @first.year + 1 end |