valid-date 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README +2 -0
  2. data/lib/valid-date.rb +16 -0
  3. data/spec/valid-date_spec.rb +23 -0
  4. metadata +65 -0
data/README ADDED
@@ -0,0 +1,2 @@
1
+ # TODO add a brief readme
2
+ # TODO Add RDoc documentation to lib/valid-date.rb
@@ -0,0 +1,16 @@
1
+ require 'activesupport'
2
+
3
+ class String
4
+ def valid_date?
5
+ unless self == ''
6
+ begin
7
+ date = self.to_date
8
+ result = true
9
+ rescue Exception => e
10
+ result = false
11
+ end
12
+ end
13
+
14
+ result
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__), "/spec_helper")
2
+
3
+ describe String do
4
+ context "knowing whether it contains a valid date" do
5
+ it "returns true when contains a valid date" do
6
+ s = "2008-10-25"
7
+
8
+ s.valid_date?.should be_true
9
+ end
10
+
11
+ it "returns false when contains an invalid date" do
12
+ s = "0000-00-00"
13
+
14
+ s.valid_date?.should_not be_true
15
+ end
16
+
17
+ it "returns nil when is empty" do
18
+ s = ""
19
+
20
+ s.valid_date?.should be_nil
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: valid-date
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Byrne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-27 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: code@patrickbyrne.net
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ files:
34
+ - lib/valid-date.rb
35
+ - README
36
+ has_rdoc: true
37
+ homepage: http://github.com/pbyrne/valid-date/
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.4
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Adds String#valid_date? method to add utility to the Rails String#to_date method. Determines whether the string contains a valid date, to check before converting to a date and avoiding an exception.
64
+ test_files:
65
+ - spec/valid-date_spec.rb