Class: Quando::Config
- Inherits:
-
Object
- Object
- Quando::Config
- Defined in:
- lib/quando/config.rb
Constant Summary collapse
- MONTHS =
[:jan, :feb, :mar, :apr, :may, :jun, :jul, :aug, :sep, :oct, :nov, :dec]
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#uniformats! ⇒ Object
Sets @formats which is an array of regexps used in succession to match and identify parts of the dates.
-
#unimonth! ⇒ Object
Sets @month_txt which is a compound of all month regexps and matches any month name.
-
#uniupdate! ⇒ Object
A single method to update all compound matchers when a part matcher was changed.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/quando/config.rb', line 16 def initialize @century = 2000 @dlm = /[ -.\/]+/ @year = /(?<year> \d{4})/x @year2 = /(?<year> \d{2})/x @month_num = /(?<month> 1[0-2] | 0?[1-9])/x @day = /(?<day> 3[0-1] | [12][0-9] | 0?[1-9])/x @jan = /JAN(?:UARY)?/xi @feb = /FEB(?:RUARY)? /xi @mar = /MAR(?:CH)?/xi @apr = /APR(?:IL)?/xi @may = /MAY/xi @jun = /JUNE?/xi @jul = /JULY?/xi @aug = /AUG(?:UST)?/xi @sep = /SEP(?:TEMBER)?/xi @oct = /OCT(?:OBER)?/xi @nov = /NOV(?:EMBER)? /xi @dec = /DEC(?:EMBER)? /xi uniupdate! end |
Instance Method Details
#uniformats! ⇒ Object
Sets @formats which is an array of regexps used in succession to match and identify parts of the dates
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/quando/config.rb', line 48 def uniformats! @formats = [ # Formats with a 4-digits year # 14.4.1965, 14/04/1965, 14-4-1965, 14 04 1965, … /\A\s* #{@day} #{@dlm} #{@month_num} #{@dlm} #{@year} \s*\z/xi, # 14-APRIL-1965, 14-apr-1965, 14/Apr/1965, … /\A\s* #{@day} #{@dlm} #{@month_txt} #{@dlm} #{@year} \s*\z/xi, # April 1965, apr.1965, … /\A\s* #{@month_txt} #{@dlm} #{@year} \s*\z/xi, # Same formats with a 2-digits year # 13.12.05, 13/12/05, 13-12-05, … /\A\s* #{@day} #{@dlm} #{@month_num} #{@dlm} #{@year2} \s*\z/xi, # April, DECEMBER, sep., … /\A\s* #{@month_txt} \s*\z/xi, ] end |
#unimonth! ⇒ Object
Sets @month_txt which is a compound of all month regexps and matches any month name
42 43 44 45 |
# File 'lib/quando/config.rb', line 42 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
A single method to update all compound matchers when a part matcher was changed
70 71 72 73 |
# File 'lib/quando/config.rb', line 70 def uniupdate! unimonth! uniformats! end |