lib/edtf/season.rb in edtf-0.0.6 vs lib/edtf/season.rb in edtf-0.0.7
- old
+ new
@@ -26,11 +26,12 @@
attr_reader :season, :year
attr_accessor :qualifier
- def_delegators :to_range, :each
+ def_delegators :to_range,
+ *Range.instance_methods(false).reject { |m| m.to_s =~ /^(each|eql?|hash)$/ }
SEASONS.each_value do |s|
define_method("#{s}?") { @season == s }
define_method("#{s}!") { @season = s }
end
@@ -63,10 +64,19 @@
self.season = arguments[1] || NORTHERN_MONTHS[Date.today.month]
self.qualifier = qualifier
end
end
+ def each
+ if block_given?
+ to_range(&Proc.new)
+ self
+ else
+ to_enum
+ end
+ end
+
def year=(new_year)
@year = new_year.to_i
end
def season=(new_season)
@@ -80,16 +90,16 @@
def to_s
'%04d-%2d%s' % [year, CODES[season], qualified? ? "^#{qualifier}" : '']
end
- alias to_edtf to_s
+ alias edtf to_s
def <=>(other)
case other
when Date
- include?(other) ? 0 : to_date <=> other
+ cover?(other) ? 0 : to_date <=> other
when Season
[year, month, qualifier] <=> [other.year, other.month, other.qualifier]
else
nil
end
@@ -102,25 +112,16 @@
rescue
false
end
def to_date
- Date.new(year, month)
+ Date.new(year, month, 1)
end
- # def include?(other)
- # case other
- # when Date
- # d = to_date
- # other >= d && other <= d.months_since(3).end_of_month
- # else
- # false
- # end
- # end
-
+ # Returns a Range that covers the season (a three month period).
def to_range
d = to_date
- d .. d.months_since(3).end_of_month
+ d .. d.months_since(2).end_of_month
end
protected
def month
\ No newline at end of file