Class: CalendariumRomanum::Util::DateParser Private
- Inherits:
-
Object
- Object
- CalendariumRomanum::Util::DateParser
- 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
- #date_range ⇒ DateEnumerator, Range readonly private
Instance Method Summary collapse
-
#initialize(date_str) ⇒ DateParser
constructor
private
A new instance of DateParser.
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_range ⇒ DateEnumerator, 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.
69 70 71 |
# File 'lib/calendarium-romanum/util.rb', line 69 def date_range @date_range end |