class Quando::Config

Constants

AUTOUPDATE
CENTURY
COMPOUND
MONTHS
OPTIONS

Public Class Methods

new() click to toggle source
# File lib/quando/config.rb, line 17
def initialize
  @dlm = /[- .\/]+/
  @year = /(?<year>\d{4})/
  @year2 = /(?<year>\d{2})/
  @month_num = /(?<month> 1[012] | 0?[1-9])/x
  @day = /(?<day> 3[01] | [12]\d | 0?[1-9])/x

  @jan = /JAN(?:UARY)?/i
  @feb = /FEB(?:RUARY)?/i
  @mar = /MAR(?:CH)?/i
  @apr = /APR(?:IL)?/i
  @may = /MAY/i
  @jun = /JUNE?/i
  @jul = /JULY?/i
  @aug = /AUG(?:UST)?/i
  @sep = /SEP(?:TEMBER)?/i
  @oct = /OCT(?:OBER)?/i
  @nov = /NOV(?:EMBER)?/i
  @dec = /DEC(?:EMBER)?/i

  self.century=(CENTURY)

  uniupdate!
end

Public Instance Methods

century() click to toggle source

@return [Integer]

# File lib/quando/config.rb, line 71
def century
  @century
end
century=(value) click to toggle source

@param value [Integer] @return [Integer]

# File lib/quando/config.rb, line 77
def century=(value)
  @century = (value == 0 ? 1 : value) || CENTURY
end
uniformats!() click to toggle source

Sets @formats which is an array of regexps used in succession to match and identify date parts

# File lib/quando/config.rb, line 49
def uniformats!
  @formats = [
    # Formats with a 4-digits year
    # 14.4.1965, 14/04/1965, 14-4-1965, 14 04 1965, …
    /^\s* #{@day} #{@dlm} #{@month_num} #{@dlm} #{@year} \s*$/xi,

    # 14-APRIL-1965, 14-apr-1965, 14/Apr/1965, …
    /^\s* #{@day} #{@dlm} #{@month_txt} #{@dlm} #{@year} \s*$/xi,

    # April 1965, apr.1965, …
    /^\s* #{@month_txt} #{@dlm} #{@year} \s*$/xi,

    # Same formats with a 2-digits year
    # 13.12.05, 13/12/05, 13-12-05, …
    /^\s* #{@day} #{@dlm} #{@month_num} #{@dlm} #{@year2} \s*$/xi,

    # April, DECEMBER, sep., …
    /^\s* #{@month_txt} \s*$/xi,
  ]
end
unimonth!() click to toggle source

Sets @month_txt, a compound of all month regexps that matches any month name

# File lib/quando/config.rb, line 43
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!() click to toggle source

A single method to update all compound matchers when a part matcher was changed

# File lib/quando/config.rb, line 82
def uniupdate!
  unimonth!
  uniformats!
end