class Pipl::DateRange
Attributes
end[R]
start[R]
Public Class Methods
from_hash(h)
click to toggle source
# File lib/pipl/fields.rb, line 717 def self.from_hash(h) start_, end_ = h[:start], h[:end] initializing_start = start_ ? Date.strptime(start_, Pipl::DATE_FORMAT) : nil initializing_end = end_ ? Date.strptime(end_, Pipl::DATE_FORMAT) : nil self.new(initializing_start, initializing_end) end
from_years_range(start_year, end_year)
click to toggle source
# File lib/pipl/fields.rb, line 713 def self.from_years_range(start_year, end_year) self.new(Date.new(start_year, 1, 1), Date.new(end_year, 12, 31)) end
new(start, end_)
click to toggle source
# File lib/pipl/fields.rb, line 687 def initialize(start, end_) @start = start @end = end_ if @start and @end and @start > @end @start, @end = @end, @start end end
Public Instance Methods
is_exact?()
click to toggle source
def ==(other)
other.instance_of?(self.class) and inspect == other.inspect
end
alias_method :eql?, :==
# File lib/pipl/fields.rb, line 701 def is_exact? @start and @end and @start == @end end
middle()
click to toggle source
# File lib/pipl/fields.rb, line 705 def middle @start and @end ? @start + ((@end - @start) / 2) : @start or @end end
to_hash()
click to toggle source
# File lib/pipl/fields.rb, line 724 def to_hash h = {} h[:start] = @start.strftime(Pipl::DATE_FORMAT) if @start h[:end] = @end.strftime(Pipl::DATE_FORMAT) if @end h end
years_range()
click to toggle source
# File lib/pipl/fields.rb, line 709 def years_range [@start.year, @end.year] if @start and @end end