From 694c3b0ce33b9665365be6db8e1b1df81983a8e9 Mon Sep 17 00:00:00 2001 From: Adam Meehan Date: Wed, 23 Dec 2009 14:52:41 +1100 Subject: [PATCH] method rename and words --- lib/validates_timeliness/formats.rb | 14 ++++++-------- spec/formats_spec.rb | 8 ++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/validates_timeliness/formats.rb b/lib/validates_timeliness/formats.rb index 81f4f36..b0585d1 100644 --- a/lib/validates_timeliness/formats.rb +++ b/lib/validates_timeliness/formats.rb @@ -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 diff --git a/spec/formats_spec.rb b/spec/formats_spec.rb index 55262c1..8513749 100644 --- a/spec/formats_spec.rb +++ b/spec/formats_spec.rb @@ -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)