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 ⇒ 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.
25 26 27 |
# File 'lib/edtf/epoch.rb', line 25 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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/edtf/epoch.rb', line 42 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
57 58 59 60 61 |
# File 'lib/edtf/epoch.rb', line 57 def ===(other) (self <=> other) == 0 rescue false end |
#cover?(other) ⇒ Boolean
36 37 38 39 40 |
# File 'lib/edtf/epoch.rb', line 36 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 ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/edtf/epoch.rb', line 63 def each if block_given? to_range.each(&Proc.new) else to_enum end end |
#edtf ⇒ Object Also known as: to_s
85 86 87 |
# File 'lib/edtf/epoch.rb', line 85 def edtf self.class.format % (year / self.class.duration) end |
#max ⇒ Object
77 78 79 |
# File 'lib/edtf/epoch.rb', line 77 def max to_date.advance(:years => self.class.duration - 1).end_of_year end |
#to_date ⇒ Object Also known as: min
71 72 73 |
# File 'lib/edtf/epoch.rb', line 71 def to_date Date.new(year).year_precision! end |
#to_range ⇒ Object
81 82 83 |
# File 'lib/edtf/epoch.rb', line 81 def to_range min..max end |