mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +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 = [
|
||||
'yyyy/mm/dd',
|
||||
'yyyy-mm-dd',
|
||||
'yyyy/mm/dd',
|
||||
'yyyy.mm.dd',
|
||||
'm/d/yy',
|
||||
'd/m/yy',
|
||||
@ -205,8 +205,8 @@ module ValidatesTimeliness
|
||||
# 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
|
||||
# regexp in start and end anchors.
|
||||
# Returns 7 part datetime array.
|
||||
def extract_date_time_values(time_string, type, strict=true)
|
||||
# Returns 7 part time array.
|
||||
def parse(time_string, type, strict=true)
|
||||
expressions = self.send("#{type}_expressions")
|
||||
time_array = nil
|
||||
expressions.each do |(regexp, processor)|
|
||||
|
||||
@ -139,27 +139,27 @@ describe ValidatesTimeliness::Formats do
|
||||
describe "extracting values" 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]
|
||||
end
|
||||
|
||||
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]
|
||||
end
|
||||
|
||||
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]
|
||||
end
|
||||
|
||||
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]
|
||||
end
|
||||
|
||||
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]
|
||||
end
|
||||
end
|
||||
@ -209,7 +209,7 @@ describe ValidatesTimeliness::Formats do
|
||||
it "should add format before specified format and be higher precedence" do
|
||||
formats.add_formats(:time, "ss:hh:nn", :before => 'hh:nn:ss')
|
||||
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]
|
||||
end
|
||||
|
||||
@ -230,10 +230,10 @@ describe ValidatesTimeliness::Formats do
|
||||
|
||||
describe "removing US formats" 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]
|
||||
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]
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user