class EDTF::Season

Constants

CODES
NORTHERN
NORTHERN_MONTHS
SEASONS
SOUTHERN
SOUTHERN_MONTHS

Attributes

approximate[RW]
qualifier[RW]
season[R]
uncertain[RW]
year[R]

Public Class Methods

current() click to toggle source
   # File lib/edtf/season.rb
22 def current
23   Date.today.season
24 end
new(*arguments) click to toggle source
   # File lib/edtf/season.rb
49 def initialize(*arguments)
50   arguments.flatten!
51   raise ArgumentError, "wrong number of arguments (#{arguments.length} for 0..3)" if arguments.length > 3
52 
53   if arguments.length == 1
54     case arguments[0]
55     when Date
56       @year, @season = arguments[0].year, NORTHERN_MONTHS[arguments[0]]
57     when Symbol, String
58       @year, @season = Date.today.year, SEASONS[CODES[arguments[0].to_sym]]
59     else
60       self.year = arguments[0]
61       @season = NORTHERN_MONTHS[Date.today.month]
62     end
63   else
64     self.year      = arguments[0] || Date.today.year
65     self.season    = arguments[1] || NORTHERN_MONTHS[Date.today.month]
66     self.qualifier = qualifier
67   end
68 end

Public Instance Methods

<=>(other) click to toggle source
    # File lib/edtf/season.rb
139 def <=>(other)
140   case other
141   when Date
142     cover?(other) ? 0 : to_date <=> other
143   when Interval, Epoch
144     [min, max] <=> [other.min, other.max]
145   when Season
146     [year, month, qualifier] <=> [other.year, other.month, other.qualifier]
147   else
148     nil
149   end
150 rescue
151   nil
152 end
===(other) click to toggle source
    # File lib/edtf/season.rb
154 def ===(other)
155   (self <=> other) == 0
156 rescue
157   false
158 end
certain!() click to toggle source
   # File lib/edtf/season.rb
84 def certain!
85   @uncertain = false
86   self
87 end
certain?() click to toggle source
   # File lib/edtf/season.rb
81 def certain?; !uncertain; end
cover?(other) click to toggle source

def next(n = 1) end

    # File lib/edtf/season.rb
104 def cover?(other)
105   return false unless other.respond_to?(:day_precision)
106   other = other.day_precision
107   min.day_precision! <= other && other <= max.day_precision!
108 end
each(&block) click to toggle source
    # File lib/edtf/season.rb
110 def each(&block)
111   if block_given?
112     to_range.each(&block)
113     self
114   else
115     to_enum
116   end
117 end
edtf() click to toggle source
    # File lib/edtf/season.rb
132 def edtf
133   '%04d-%2d%s' % [year, CODES[season], qualified? ? "^#{qualifier}" : '']
134 end
Also aliased as: to_s
max() click to toggle source
    # File lib/edtf/season.rb
166 def max
167   to_date.months_since(2).end_of_month
168 end
min()
Alias for: to_date
precise!() click to toggle source
   # File lib/edtf/season.rb
89 def precise!
90   @approximate = false
91 end
precise?() click to toggle source
   # File lib/edtf/season.rb
82 def precise?; !approximate; end
qualified?() click to toggle source
    # File lib/edtf/season.rb
130 def qualified?; !!@qualifier; end
season=(new_season) click to toggle source
    # File lib/edtf/season.rb
123 def season=(new_season)
124   @season = SEASONS[new_season] || SEASONS[CODES[new_season]] ||
125     raise(ArgumentError, "unknown season/format: #{new_season.inspect})")
126 end
season?() click to toggle source
    # File lib/edtf/season.rb
128 def season?; true; end
succ() click to toggle source

Returns the next season.

   # File lib/edtf/season.rb
94 def succ
95   s = dup
96   s.season = next_season_code
97   s.year = year + 1 if s.first?
98   s
99 end
to_date() click to toggle source
    # File lib/edtf/season.rb
160 def to_date
161   Date.new(year, month, 1)
162 end
Also aliased as: min
to_range() click to toggle source

Returns a Range that covers the season (a three month period).

    # File lib/edtf/season.rb
171 def to_range
172   min .. max
173 end
to_s()
Alias for: edtf
year=(new_year) click to toggle source
    # File lib/edtf/season.rb
119 def year=(new_year)
120   @year = new_year.to_i
121 end

Protected Instance Methods

month() click to toggle source
    # File lib/edtf/season.rb
177 def month
178   NORTHERN[@season][0]
179 end
next_season_code(by = 1) click to toggle source
    # File lib/edtf/season.rb
185 def next_season_code(by = 1)
186   ((season_code + by) % 4) + 20
187 end
season_code() click to toggle source
    # File lib/edtf/season.rb
181 def season_code
182   CODES[season]
183 end