class EDTF::Epoch

Attributes

duration[R]
format[R]
get[R]
year[R]

Public Class Methods

new(year = 0) click to toggle source
   # File lib/edtf/epoch.rb
26 def initialize(year = 0)
27   self.year = year
28 end

Private Class Methods

current() click to toggle source
   # File lib/edtf/epoch.rb
12 def current
13   new(Date.today.year)
14 end

Public Instance Methods

<=>(other) click to toggle source
   # File lib/edtf/epoch.rb
43 def <=>(other)
44   case other
45   when Date
46     cover?(other) ? 0 : to_date <=> other
47   when Interval, Season
48     [min, max] <=> [other.min, other.max]
49   when Epoch
50     [year, self.class.duration] <=> [other.year, other.class.duration]
51   else
52     nil
53   end
54 rescue
55   nil
56 end
===(other) click to toggle source
   # File lib/edtf/epoch.rb
58 def ===(other)
59   (self <=> other) == 0
60 rescue
61   false
62 end
cover?(other) click to toggle source
   # File lib/edtf/epoch.rb
37 def cover?(other)
38   return false unless other.respond_to?(:day_precision)
39   other = other.day_precision
40   min.day_precision! <= other && other <= max.day_precision!
41 end
each(&block) click to toggle source
   # File lib/edtf/epoch.rb
64 def each(&block)
65   if block_given?
66     to_range.each(&block)
67   else
68     to_enum
69   end
70 end
edtf() click to toggle source
   # File lib/edtf/epoch.rb
86 def edtf
87   self.class.format % (year / self.class.duration)
88 end
Also aliased as: to_s
max() click to toggle source
   # File lib/edtf/epoch.rb
78 def max
79   to_date.advance(:years => self.class.duration - 1).end_of_year
80 end
min()
Alias for: to_date
set(year)
Alias for: year=
to_date() click to toggle source
   # File lib/edtf/epoch.rb
72 def to_date
73   Date.new(year).year_precision!
74 end
Also aliased as: min
to_range() click to toggle source
   # File lib/edtf/epoch.rb
82 def to_range
83   min..max
84 end
to_s()
Alias for: edtf
year=(year) click to toggle source
   # File lib/edtf/epoch.rb
30 def year=(year)
31   @year = (year / self.class.duration) * self.class.duration
32 end
Also aliased as: set