Class: Quando::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/quando/config.rb

Constant Summary collapse

AVAILABLE_OPTIONS =
[
  :dlm, :year, :day,
  :jan, :feb, :mar, :apr, :may, :jun, :jul, :aug, :sep, :oct, :nov, :dec,
  :month_num, :month_txt,
  :formats
]
MONTHS =
[:jan, :feb, :mar, :apr, :may, :jun, :jul, :aug, :sep, :oct, :nov, :dec]

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/quando/config.rb', line 18

def initialize
  @dlm = /[ -.\/\\]/
  @year = /(?<year>(?:\d{2})|(?:\d{4}))/i
  @month_num = /(?<month>(?:1[0-2])|(?:0?[1-9]))/
  @day = /(?<day>(?:[3][0-1])|(?:[1-2][0-9])|(?:0?[1-9]))/

  @jan = /(?:JANUARY)|(?:JAN\.?)/i
  @feb = /(?:FEBRUARY)|(?:FEB\.?)/i
  @mar = /(?:MARCH)|(?:MAR\.?)/i
  @apr = /(?:APRIL)|(?:APR\.?)/i
  @may = /(?:MAY\.?)/i
  @jun = /(?:JUNE)|(?:JUN\.?)/i
  @jul = /(?:JULY)|(?:JUL\.?)/i
  @aug = /(?:AUGUST)|(?:AUG\.?)/i
  @sep = /(?:SEPTEMBER)|(?:SEPT?\.?)/i
  @oct = /(?:OCTOBER)|(?:OCT\.?)/i
  @nov = /(?:NOVEMBER)|(?:NOV\.?)/i
  @dec = /(?:DECEMBER)|(?:DEC\.?)/i

  uniupdate!
end

Instance Method Details

#uniformats!Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/quando/config.rb', line 40

def uniformats!
  @formats = [
    # 14.4.1965, 14/04/1965, 13-12-05
    /\A\s* #{@day} #{@dlm} #{@month_num} #{@dlm} #{@year} \s*\z/xi,

    # 14-APRIL-1965, 14-apr-65, 13/Dec/05, …
    /\A\s* #{@day} #{@dlm} #{@month_txt} #{@dlm} #{@year} \s*\z/xi,

    # April 1965, apr.1965, DEC-05, …
    /\A\s* #{@month_txt} #{@dlm} #{@year} \s*\z/xi,

    # April, DECEMBER, apr., …
    /\A\s* #{@month_txt} \s*\z/xi,
  ]
end

#unimonth!Object



56
57
58
59
# File 'lib/quando/config.rb', line 56

def unimonth!
  all_months_txt_rxs = MONTHS.map { |m| instance_variable_get("@#{m}".to_sym) }.join('|')
  @month_txt = Regexp.new("(?<month>#{all_months_txt_rxs})", true)
end

#uniupdate!Object



61
62
63
64
# File 'lib/quando/config.rb', line 61

def uniupdate!
  unimonth!
  uniformats!
end