mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
method rename and words
This commit is contained in:
parent
a859827af4
commit
694c3b0ce3
@ -2,11 +2,9 @@ require 'date'
|
||||
|
||||
module ValidatesTimeliness
|
||||
|
||||
# A date and time format regular expression generator. Allows you to
|
||||
# construct a date, time or datetime format using predefined tokens in
|
||||
# a string. This makes it much easier to catalogue and customize the formats
|
||||
# rather than dealing directly with regular expressions. The formats are then
|
||||
# compiled into regular expressions for use validating date or time strings.
|
||||
# A date and time parsing library which allows you to add custom formats using
|
||||
# simple predefined tokens. This makes it much easier to catalogue and customize
|
||||
# the formats rather than dealing directly with regular expressions.
|
||||
#
|
||||
# Formats can be added or removed to customize the set of valid date or time
|
||||
# string values.
|
||||
@ -298,8 +296,8 @@ module ValidatesTimeliness
|
||||
|
||||
private
|
||||
|
||||
# Compile formats into validation regexps and format procs
|
||||
def format_expression_generator(string_format)
|
||||
# Generate regular expression and processor from format string
|
||||
def generate_format_expression(string_format)
|
||||
regexp = string_format.dup
|
||||
order = {}
|
||||
regexp.gsub!(/([\.\\])/, '\\\\\1') # escapes dots and backslashes
|
||||
@ -339,7 +337,7 @@ module ValidatesTimeliness
|
||||
end
|
||||
|
||||
def compile_formats(formats)
|
||||
formats.map { |format| [ format, *format_expression_generator(format) ] }
|
||||
formats.map { |format| [ format, *generate_format_expression(format) ] }
|
||||
end
|
||||
|
||||
# Pick expression set and combine date and datetimes for
|
||||
|
||||
@ -5,7 +5,7 @@ describe ValidatesTimeliness::Formats do
|
||||
describe "format proc generator" do
|
||||
it "should generate proc which outputs date array with values in correct order" do
|
||||
generate_proc('yyyy-mm-dd').call('2000', '1', '2').should == [2000,1,2,0,0,0,0]
|
||||
end
|
||||
end
|
||||
|
||||
it "should generate proc which outputs date array from format with different order" do
|
||||
generate_proc('dd/mm/yyyy').call('2', '1', '2000').should == [2000,1,2,0,0,0,0]
|
||||
@ -289,15 +289,15 @@ describe ValidatesTimeliness::Formats do
|
||||
|
||||
def generate_regexp(format)
|
||||
# wrap in line start and end anchors to emulate extract values method
|
||||
/\A#{formats.send(:format_expression_generator, format)[0]}\Z/
|
||||
/\A#{formats.send(:generate_format_expression, format)[0]}\Z/
|
||||
end
|
||||
|
||||
def generate_regexp_str(format)
|
||||
formats.send(:format_expression_generator, format)[0].inspect
|
||||
formats.send(:generate_format_expression, format)[0].inspect
|
||||
end
|
||||
|
||||
def generate_proc(format)
|
||||
formats.send(:format_expression_generator, format)[1]
|
||||
formats.send(:generate_format_expression, format)[1]
|
||||
end
|
||||
|
||||
def delete_format(type, format)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user