Class: CalendariumRomanum::Util::DateParser
- Inherits:
-
Object
- Object
- CalendariumRomanum::Util::DateParser
- Defined in:
- lib/calendarium-romanum/util.rb
Instance Attribute Summary collapse
-
#date_range ⇒ Object
readonly
Returns the value of attribute date_range.
Instance Method Summary collapse
-
#initialize(date_str) ⇒ DateParser
constructor
A new instance of DateParser.
Constructor Details
#initialize(date_str) ⇒ DateParser
Returns a new instance of DateParser.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/calendarium-romanum/util.rb', line 42 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 ⇒ Object (readonly)
Returns the value of attribute date_range.
41 42 43 |
# File 'lib/calendarium-romanum/util.rb', line 41 def date_range @date_range end |