lib/validates_timeliness/parser.rb in validates_timeliness-3.0.0.beta vs lib/validates_timeliness/parser.rb in validates_timeliness-3.0.0.beta.2

- old
+ new

@@ -8,20 +8,12 @@ # # Formats can be added or removed to customize the set of valid date or time # string values. # class Parser - cattr_accessor :time_formats, - :date_formats, - :datetime_formats, - :time_expressions, - :date_expressions, - :datetime_expressions, - :format_tokens, - :format_proc_args + cattr_reader :time_expressions, :date_expressions, :datetime_expressions - # Set the threshold value for a two digit year to be considered last century # # Default: 30 # # Example: @@ -71,10 +63,11 @@ # # Any other invalid combination of repeating tokens will be swallowed up # by the next lowest length valid repeating token (e.g. yyy will be # replaced with yy) + cattr_accessor :time_formats @@time_formats = [ 'hh:nn:ss', 'hh-nn-ss', 'h:nn', 'h.nn', @@ -85,10 +78,11 @@ 'h nn_ampm', 'h-nn_ampm', 'h_ampm' ] + cattr_accessor :date_formats @@date_formats = [ 'yyyy-mm-dd', 'yyyy/mm/dd', 'yyyy.mm.dd', 'm/d/yy', @@ -99,10 +93,11 @@ 'dd-mm-yyyy', 'd.m.yy', 'd mmm yy' ] + cattr_accessor :datetime_formats @@datetime_formats = [ 'yyyy-mm-dd hh:nn:ss', 'yyyy-mm-dd h:nn', 'yyyy-mm-dd h:nn_ampm', 'yyyy-mm-dd hh:nn:ss.u', @@ -130,15 +125,15 @@ # # The token regexp should only use a capture group if 'look-behind' anchor # is required. The first capture group will be considered a literal and put # into the validation regexp string as-is. This is a hack. # + cattr_accessor :format_tokens @@format_tokens = { 'ddd' => [ '\w{3,9}' ], 'dd' => [ '\d{2}', :day ], 'd' => [ '\d{1,2}', :day ], - 'ampm' => [ '[aApP]\.?[mM]\.?', :meridian ], 'mmm' => [ '\w{3,9}', :month ], 'mm' => [ '\d{2}', :month ], 'm' => [ '\d{1,2}', :month ], 'yyyy' => [ '\d{4}', :year ], 'yy' => [ '\d{4}|\d{2}', :year ], @@ -147,10 +142,11 @@ 'nn' => [ '\d{2}', :min ], 'n' => [ '\d{1,2}', :min ], 'ss' => [ '\d{2}', :sec ], 's' => [ '\d{1,2}', :sec ], 'u' => [ '\d{1,6}', :usec ], + 'ampm' => [ '[aApP]\.?[mM]\.?', :meridian ], 'zo' => [ '[+-]\d{2}:?\d{2}', :offset ], 'tz' => [ '[A-Z]{1,4}' ], '_' => [ '\s?' ] } @@ -161,10 +157,11 @@ # won't be placed in the array. # # The code can be used to manipulate the arg value if required, otherwise # should just be the arg name. # + cattr_accessor :format_proc_args @@format_proc_args = { :year => [0, 'y', 'unambiguous_year(y)'], :month => [1, 'm', 'month_index(m)'], :day => [2, 'd', 'd'], :hour => [3, 'h', 'full_hour(h, md ||= nil)'], @@ -172,10 +169,9 @@ :sec => [5, 's', 's'], :usec => [6, 'u', 'microseconds(u)'], :offset => [7, 'z', 'offset_in_seconds(z)'], :meridian => [nil, 'md', nil] } - @@type_wrapper = { :date => [/\A/, nil], :time => [nil , /\Z/], :datetime => [/\A/, /\Z/]