pbyrne-valid-date 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +13 -2
- data/lib/valid-date.rb +9 -0
- metadata +2 -2
data/README
CHANGED
@@ -1,2 +1,13 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
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.
|
2
|
+
|
3
|
+
Examples:
|
4
|
+
|
5
|
+
"2008-01-01".valid_date? #=> true
|
6
|
+
"20080101".valid_date? #=> true
|
7
|
+
"0000-00-00".valid_date? #=> false
|
8
|
+
"".valid_date? #=> nil
|
9
|
+
|
10
|
+
|
11
|
+
This gem is released under a broad open-source license. See LICENSE for more details.
|
12
|
+
|
13
|
+
# TODO consider switching from manual gemspec to using jeweler (the recommended tool by github to manage the gemspec)
|
data/lib/valid-date.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
|
+
# todo should this require be in the gemspec, since we assume active support is already loaded when using the gem, per the gemspec?
|
1
2
|
require 'activesupport'
|
2
3
|
|
3
4
|
class String
|
5
|
+
#
|
6
|
+
# Determines whether the string contains a valid date for use with the Rails String#to_date method.
|
7
|
+
#
|
8
|
+
# "2008-01-01".valid_date? #=> true
|
9
|
+
# "20080101".valid_date? #=> true
|
10
|
+
# "0000-00-00".valid_date? #=> false
|
11
|
+
# "".valid_date? #=> nil
|
12
|
+
#
|
4
13
|
def valid_date?
|
5
14
|
unless self == ''
|
6
15
|
begin
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pbyrne-valid-date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Byrne
|
@@ -33,7 +33,7 @@ extra_rdoc_files:
|
|
33
33
|
files:
|
34
34
|
- lib/valid-date.rb
|
35
35
|
- README
|
36
|
-
has_rdoc:
|
36
|
+
has_rdoc: true
|
37
37
|
homepage: http://github.com/pbyrne/valid-date/
|
38
38
|
post_install_message:
|
39
39
|
rdoc_options: []
|