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
|
module ValidatesTimeliness
|
||||||
|
|
||||||
# A date and time format regular expression generator. Allows you to
|
# A date and time parsing library which allows you to add custom formats using
|
||||||
# construct a date, time or datetime format using predefined tokens in
|
# simple predefined tokens. This makes it much easier to catalogue and customize
|
||||||
# a string. This makes it much easier to catalogue and customize the formats
|
# the formats rather than dealing directly with regular expressions.
|
||||||
# rather than dealing directly with regular expressions. The formats are then
|
|
||||||
# compiled into regular expressions for use validating date or time strings.
|
|
||||||
#
|
#
|
||||||
# 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.
|
||||||
@ -298,8 +296,8 @@ module ValidatesTimeliness
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Compile formats into validation regexps and format procs
|
# Generate regular expression and processor from format string
|
||||||
def format_expression_generator(string_format)
|
def generate_format_expression(string_format)
|
||||||
regexp = string_format.dup
|
regexp = string_format.dup
|
||||||
order = {}
|
order = {}
|
||||||
regexp.gsub!(/([\.\\])/, '\\\\\1') # escapes dots and backslashes
|
regexp.gsub!(/([\.\\])/, '\\\\\1') # escapes dots and backslashes
|
||||||
@ -339,7 +337,7 @@ module ValidatesTimeliness
|
|||||||
end
|
end
|
||||||
|
|
||||||
def compile_formats(formats)
|
def compile_formats(formats)
|
||||||
formats.map { |format| [ format, *format_expression_generator(format) ] }
|
formats.map { |format| [ format, *generate_format_expression(format) ] }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Pick expression set and combine date and datetimes for
|
# Pick expression set and combine date and datetimes for
|
||||||
|
|||||||
@ -5,7 +5,7 @@ describe ValidatesTimeliness::Formats do
|
|||||||
describe "format proc generator" do
|
describe "format proc generator" do
|
||||||
it "should generate proc which outputs date array with values in correct order" 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]
|
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
|
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]
|
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)
|
def generate_regexp(format)
|
||||||
# wrap in line start and end anchors to emulate extract values method
|
# 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
|
end
|
||||||
|
|
||||||
def generate_regexp_str(format)
|
def generate_regexp_str(format)
|
||||||
formats.send(:format_expression_generator, format)[0].inspect
|
formats.send(:generate_format_expression, format)[0].inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_proc(format)
|
def generate_proc(format)
|
||||||
formats.send(:format_expression_generator, format)[1]
|
formats.send(:generate_format_expression, format)[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_format(type, format)
|
def delete_format(type, format)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user