Class: CalendariumRomanum::CLI::DateParser Private

Inherits:
Object
  • Object
show all
Defined in:
lib/calendarium-romanum/cli/date_parser.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.

Class Method Summary collapse

Class Method Details

.build_range(*args) ⇒ Object

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.


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/calendarium-romanum/cli/date_parser.rb', line 17

def self.build_range(*args)
  case args.size
  when 1
    Util::Year.new(*args)
  when 2
    Util::Month.new(*args)
  else
    date = Date.new(*args)
    date..date
  end
end

.parse(date_str) ⇒ Object

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.


5
6
7
8
9
10
11
12
13
14
15
# File 'lib/calendarium-romanum/cli/date_parser.rb', line 5

def self.parse(date_str)
  /(?<year>\d{4})([\/-](?<month>\d{1,2})([\/-](?<day>\d{1,2}))?)?/.match(date_str) do |m|
    date_segments =
      %i(year month day)
        .collect {|name| m[name] }
        .compact
        .collect(&:to_i)

    build_range(*date_segments)
  end || raise(ArgumentError.new('Unparseable date'))
end