Class: CalendariumRomanum::Util::DateParser Private

Inherits:
Object
  • Object
show all
Defined in:
lib/calendarium-romanum/util.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date_str) ⇒ DateParser

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of DateParser.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/calendarium-romanum/util.rb', line 51

def initialize(date_str)
  if date_str =~ /((\d{4})(\/|-)?(\d{0,2})(\/|-)?(\d{0,2}))\z/ # Accepts YYYY-MM-DD, YYYY/MM/DD where both day and month are optional
    year = Regexp.last_match(2).to_i
    month = Regexp.last_match(4).to_i
    day = Regexp.last_match(6).to_i
    @date_range = if (day == 0) && (month == 0) # Only year is given
                    Year.new(year)
                  elsif day == 0 # Year and month are given
                    Month.new(year, month)
                  else
                    Date.new(year, month, day)..Date.new(year, month, day)
                  end
  else
    raise ArgumentError, 'Unparseable date'
  end
end

Instance Attribute Details

#date_rangeDateEnumerator, Range (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



69
70
71
# File 'lib/calendarium-romanum/util.rb', line 69

def date_range
  @date_range
end