Class: Montrose::Month

Inherits:
Object
  • Object
show all
Extended by:
Utils
Defined in:
lib/montrose/month.rb

Constant Summary collapse

NAMES =

starts with nil to match 1-12 numbering

::Date::MONTHNAMES
NUMBERS =
NAMES.map.with_index { |_n, i| i.to_s }.slice(1, 12)

Constants included from Utils

Utils::MAX_DAYS_IN_MONTH, Utils::MAX_DAYS_IN_YEAR, Utils::MAX_HOURS_IN_DAY, Utils::MAX_WEEKS_IN_YEAR

Class Method Summary collapse

Methods included from Utils

as_date, as_time, current_time, days_in_month, days_in_year, normalize_time, parse_time, to_index

Class Method Details

.namesObject



22
23
24
# File 'lib/montrose/month.rb', line 22

def names
  NAMES
end

.number(name) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/montrose/month.rb', line 30

def number(name)
  case name
  when Symbol, String
    string = name.to_s
    NAMES.index(string.titleize) || number(to_index(string))
  when 1..12
    name
  end
end

.number!(name) ⇒ Object



40
41
42
43
44
# File 'lib/montrose/month.rb', line 40

def number!(name)
  numbers = NAMES.map.with_index { |_n, i| i.to_s }.slice(1, 12)
  number(name) || raise(ConfigurationError,
    "Did not recognize month #{name}, must be one of #{(NAMES + numbers).inspect}")
end

.numbersObject



26
27
28
# File 'lib/montrose/month.rb', line 26

def numbers
  NUMBERS
end

.parse(value) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/montrose/month.rb', line 9

def parse(value)
  case value
  when String
    parse(value.split(",").compact)
  when Array
    value.map { |m|
      Montrose::Month.number!(m)
    }.presence
  else
    parse(Array(value))
  end
end