mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-23 06:16:44 +00:00
renamed extract method to parse and updated specs
This commit is contained in:
parent
e8bba051c9
commit
89f12b3a25
@ -70,8 +70,8 @@ module ValidatesTimeliness
|
|||||||
]
|
]
|
||||||
|
|
||||||
@@date_formats = [
|
@@date_formats = [
|
||||||
'yyyy/mm/dd',
|
|
||||||
'yyyy-mm-dd',
|
'yyyy-mm-dd',
|
||||||
|
'yyyy/mm/dd',
|
||||||
'yyyy.mm.dd',
|
'yyyy.mm.dd',
|
||||||
'm/d/yy',
|
'm/d/yy',
|
||||||
'd/m/yy',
|
'd/m/yy',
|
||||||
@ -205,8 +205,8 @@ module ValidatesTimeliness
|
|||||||
# Loop through format expressions for type and call proc on matches. Allow
|
# Loop through format expressions for type and call proc on matches. Allow
|
||||||
# pre or post match strings to exist if strict is false. Otherwise wrap
|
# pre or post match strings to exist if strict is false. Otherwise wrap
|
||||||
# regexp in start and end anchors.
|
# regexp in start and end anchors.
|
||||||
# Returns 7 part datetime array.
|
# Returns 7 part time array.
|
||||||
def extract_date_time_values(time_string, type, strict=true)
|
def parse(time_string, type, strict=true)
|
||||||
expressions = self.send("#{type}_expressions")
|
expressions = self.send("#{type}_expressions")
|
||||||
time_array = nil
|
time_array = nil
|
||||||
expressions.each do |(regexp, processor)|
|
expressions.each do |(regexp, processor)|
|
||||||
|
|||||||
@ -139,27 +139,27 @@ describe ValidatesTimeliness::Formats do
|
|||||||
describe "extracting values" do
|
describe "extracting values" do
|
||||||
|
|
||||||
it "should return time array from date string" do
|
it "should return time array from date string" do
|
||||||
time_array = formats.extract_date_time_values('12:13:14', :time, true)
|
time_array = formats.parse('12:13:14', :time, true)
|
||||||
time_array.should == [0,0,0,12,13,14,0]
|
time_array.should == [0,0,0,12,13,14,0]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return date array from time string" do
|
it "should return date array from time string" do
|
||||||
time_array = formats.extract_date_time_values('2000-02-01', :date, true)
|
time_array = formats.parse('2000-02-01', :date, true)
|
||||||
time_array.should == [2000,2,1,0,0,0,0]
|
time_array.should == [2000,2,1,0,0,0,0]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return datetime array from string value" do
|
it "should return datetime array from string value" do
|
||||||
time_array = formats.extract_date_time_values('2000-02-01 12:13:14', :datetime, true)
|
time_array = formats.parse('2000-02-01 12:13:14', :datetime, true)
|
||||||
time_array.should == [2000,2,1,12,13,14,0]
|
time_array.should == [2000,2,1,12,13,14,0]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should ignore time when extracting date and strict is false" do
|
it "should ignore time when extracting date and strict is false" do
|
||||||
time_array = formats.extract_date_time_values('2000-02-01 12:12', :date, false)
|
time_array = formats.parse('2000-02-01 12:12', :date, false)
|
||||||
time_array.should == [2000,2,1,0,0,0,0]
|
time_array.should == [2000,2,1,0,0,0,0]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should ignore date when extracting time and strict is false" do
|
it "should ignore date when extracting time and strict is false" do
|
||||||
time_array = formats.extract_date_time_values('2000-02-01 12:12', :time, false)
|
time_array = formats.parse('2000-02-01 12:12', :time, false)
|
||||||
time_array.should == [0,0,0,12,12,0,0]
|
time_array.should == [0,0,0,12,12,0,0]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -209,7 +209,7 @@ describe ValidatesTimeliness::Formats do
|
|||||||
it "should add format before specified format and be higher precedence" do
|
it "should add format before specified format and be higher precedence" do
|
||||||
formats.add_formats(:time, "ss:hh:nn", :before => 'hh:nn:ss')
|
formats.add_formats(:time, "ss:hh:nn", :before => 'hh:nn:ss')
|
||||||
validate("59:23:58", :time).should be_true
|
validate("59:23:58", :time).should be_true
|
||||||
time_array = formats.extract_date_time_values('59:23:58', :time)
|
time_array = formats.parse('59:23:58', :time)
|
||||||
time_array.should == [0,0,0,23,58,59,0]
|
time_array.should == [0,0,0,23,58,59,0]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -230,10 +230,10 @@ describe ValidatesTimeliness::Formats do
|
|||||||
|
|
||||||
describe "removing US formats" do
|
describe "removing US formats" do
|
||||||
it "should validate a date as European format when US formats removed" do
|
it "should validate a date as European format when US formats removed" do
|
||||||
time_array = formats.extract_date_time_values('01/02/2000', :date)
|
time_array = formats.parse('01/02/2000', :date)
|
||||||
time_array.should == [2000, 1, 2,0,0,0,0]
|
time_array.should == [2000, 1, 2,0,0,0,0]
|
||||||
formats.remove_us_formats
|
formats.remove_us_formats
|
||||||
time_array = formats.extract_date_time_values('01/02/2000', :date)
|
time_array = formats.parse('01/02/2000', :date)
|
||||||
time_array.should == [2000, 2, 1,0,0,0,0]
|
time_array.should == [2000, 2, 1,0,0,0,0]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user