parser should be a module not a class

This commit is contained in:
Adam Meehan 2010-10-11 15:49:01 +11:00
parent 3f72f31063
commit 71162d5614

View File

@ -9,8 +9,8 @@ module ValidatesTimeliness
# Formats can be added or removed to customize the set of valid date or time # Formats can be added or removed to customize the set of valid date or time
# string values. # string values.
# #
class Parser module Parser
cattr_reader :time_expressions, :date_expressions, :datetime_expressions mattr_reader :time_expressions, :date_expressions, :datetime_expressions
# Set the threshold value for a two digit year to be considered last century # Set the threshold value for a two digit year to be considered last century
# #
@ -20,7 +20,7 @@ module ValidatesTimeliness
# year = '29' is considered 2029 # year = '29' is considered 2029
# year = '30' is considered 1930 # year = '30' is considered 1930
# #
cattr_accessor :ambiguous_year_threshold mattr_accessor :ambiguous_year_threshold
self.ambiguous_year_threshold = 30 self.ambiguous_year_threshold = 30
# Format tokens: # Format tokens:
@ -57,7 +57,7 @@ module ValidatesTimeliness
# by the next lowest length valid repeating token (e.g. yyy will be # by the next lowest length valid repeating token (e.g. yyy will be
# replaced with yy) # replaced with yy)
cattr_accessor :time_formats mattr_accessor :time_formats
@@time_formats = [ @@time_formats = [
'hh:nn:ss', 'hh:nn:ss',
'hh-nn-ss', 'hh-nn-ss',
@ -72,7 +72,7 @@ module ValidatesTimeliness
'h_ampm' 'h_ampm'
] ]
cattr_accessor :date_formats mattr_accessor :date_formats
@@date_formats = [ @@date_formats = [
'yyyy-mm-dd', 'yyyy-mm-dd',
'yyyy/mm/dd', 'yyyy/mm/dd',
@ -87,7 +87,7 @@ module ValidatesTimeliness
'd mmm yy' 'd mmm yy'
] ]
cattr_accessor :datetime_formats mattr_accessor :datetime_formats
@@datetime_formats = [ @@datetime_formats = [
'yyyy-mm-dd hh:nn:ss', 'yyyy-mm-dd hh:nn:ss',
'yyyy-mm-dd h:nn', 'yyyy-mm-dd h:nn',
@ -111,7 +111,7 @@ module ValidatesTimeliness
# All tokens available for format construction. The token array is made of # All tokens available for format construction. The token array is made of
# regexp and key for format component mapping, if any. # regexp and key for format component mapping, if any.
# #
cattr_accessor :format_tokens mattr_accessor :format_tokens
@@format_tokens = { @@format_tokens = {
'ddd' => [ '\w{3,9}' ], 'ddd' => [ '\w{3,9}' ],
'dd' => [ '\d{2}', :day ], 'dd' => [ '\d{2}', :day ],
@ -143,7 +143,7 @@ module ValidatesTimeliness
# If the position is nil, then the value won't be put in the time array. If the # If the position is nil, then the value won't be put in the time array. If the
# code slot is empty, then just the raw value is used. # code slot is empty, then just the raw value is used.
# #
cattr_accessor :format_components mattr_accessor :format_components
@@format_components = { @@format_components = {
:year => [ 0, 'unambiguous_year(year)'], :year => [ 0, 'unambiguous_year(year)'],
:month => [ 1, 'month_index(month)'], :month => [ 1, 'month_index(month)'],