Class: EDTF::Epoch
- Inherits:
-
Object
- Object
- EDTF::Epoch
- Extended by:
- Forwardable
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/edtf/epoch.rb
Class Attribute Summary collapse
-
.duration ⇒ Object
readonly
Returns the value of attribute duration.
-
.format ⇒ Object
readonly
Returns the value of attribute format.
Instance Attribute Summary collapse
-
#year ⇒ Object
(also: #get)
Returns the value of attribute year.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #===(other) ⇒ Object
- #cover?(other) ⇒ Boolean
- #each(&block) ⇒ Object
- #edtf ⇒ Object (also: #to_s)
-
#initialize(year = 0) ⇒ Epoch
constructor
A new instance of Epoch.
- #max ⇒ Object
- #to_date ⇒ Object (also: #min)
- #to_range ⇒ Object
Constructor Details
#initialize(year = 0) ⇒ Epoch
Returns a new instance of Epoch.
26 27 28 |
# File 'lib/edtf/epoch.rb', line 26 def initialize(year = 0) self.year = year end |
Class Attribute Details
.duration ⇒ Object (readonly)
Returns the value of attribute duration.
10 11 12 |
# File 'lib/edtf/epoch.rb', line 10 def duration @duration end |
.format ⇒ Object (readonly)
Returns the value of attribute format.
10 11 12 |
# File 'lib/edtf/epoch.rb', line 10 def format @format end |
Instance Attribute Details
#year ⇒ Object Also known as: get
Returns the value of attribute year.
19 20 21 |
# File 'lib/edtf/epoch.rb', line 19 def year @year end |
Class Method Details
.current ⇒ Object
12 13 14 |
# File 'lib/edtf/epoch.rb', line 12 def current new(Date.today.year) end |
Instance Method Details
#<=>(other) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/edtf/epoch.rb', line 43 def <=>(other) case other when Date cover?(other) ? 0 : to_date <=> other when Interval, Season [min, max] <=> [other.min, other.max] when Epoch [year, self.class.duration] <=> [other.year, other.class.duration] else nil end rescue nil end |
#===(other) ⇒ Object
58 59 60 61 62 |
# File 'lib/edtf/epoch.rb', line 58 def ===(other) (self <=> other) == 0 rescue false end |
#cover?(other) ⇒ Boolean
37 38 39 40 41 |
# File 'lib/edtf/epoch.rb', line 37 def cover?(other) return false unless other.respond_to?(:day_precision) other = other.day_precision min.day_precision! <= other && other <= max.day_precision! end |
#each(&block) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/edtf/epoch.rb', line 64 def each(&block) if block_given? to_range.each(&block) else to_enum end end |
#edtf ⇒ Object Also known as: to_s
86 87 88 |
# File 'lib/edtf/epoch.rb', line 86 def edtf self.class.format % (year / self.class.duration) end |
#max ⇒ Object
78 79 80 |
# File 'lib/edtf/epoch.rb', line 78 def max to_date.advance(:years => self.class.duration - 1).end_of_year end |
#to_date ⇒ Object Also known as: min
72 73 74 |
# File 'lib/edtf/epoch.rb', line 72 def to_date Date.new(year).year_precision! end |
#to_range ⇒ Object
82 83 84 |
# File 'lib/edtf/epoch.rb', line 82 def to_range min..max end |