Class: Warekky::Era

Inherits:
Object
  • Object
show all
Defined in:
lib/warekky/era.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @key, @sign = key.to_sym, sign.to_s.freeze
  @first, @last = to_date(first), to_date(last)
  @options = (options || {}).freeze
end

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



5
6
7
# File 'lib/warekky/era.rb', line 5

def first
  @first
end

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/warekky/era.rb', line 5

def key
  @key
end

#lastObject (readonly)

Returns the value of attribute last.



5
6
7
# File 'lib/warekky/era.rb', line 5

def last
  @last
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/warekky/era.rb', line 5

def options
  @options
end

#signObject (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)
  @options[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

#nameObject



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