sixarm_ruby_to_id 1.0.4 → 1.0.6
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.md +6 -0
- data/lib/sixarm_ruby_to_id/date.rb +1 -1
- data/lib/sixarm_ruby_to_id/hash.rb +18 -0
- data/lib/sixarm_ruby_to_id.rb +1 -1
- data/test/sixarm_ruby_to_id_test/hash_test.rb +41 -0
- data/test/sixarm_ruby_to_id_test.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +5 -2
- metadata.gz.sig +2 -4
data/README.md
CHANGED
@@ -58,9 +58,15 @@ Cast a comma-separated list to string ids:
|
|
58
58
|
|
59
59
|
"a,b,c".to_s_ids #=> ["a", "b", "c"]
|
60
60
|
|
61
|
+
Cast a hash of year, month, day to a date id YYYY-MM-DD:
|
62
|
+
|
63
|
+
{year: "2000", month: "12", day: "31"}.to_date_id #=> "2000-12-31"
|
64
|
+
|
65
|
+
|
61
66
|
|
62
67
|
## Changes
|
63
68
|
|
69
|
+
* 2012-08-21 1.0.6 Add Hash#to_date_id
|
64
70
|
* 2012-08-11 1.0.0 Publish
|
65
71
|
|
66
72
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Hash
|
2
|
+
|
3
|
+
|
4
|
+
# Cast me to a date id by parsing fields for year, month, day.
|
5
|
+
#
|
6
|
+
# hash = {year: "2000", month: "12", day: "31"}
|
7
|
+
# hash.to_date_id
|
8
|
+
# #=> "2000-12-31"
|
9
|
+
#
|
10
|
+
def to_date_id
|
11
|
+
year = self["year"] || self[:year]
|
12
|
+
month = self["month"] || self[:month]
|
13
|
+
day = self["day"] || self[:day]
|
14
|
+
year && month && day ? sprintf("%4.4d-%2.2d-%2.2d", year.to_i, month.to_i, day.to_i) : nil
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
end
|
data/lib/sixarm_ruby_to_id.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'sixarm_ruby_to_id'
|
4
|
+
|
5
|
+
describe Hash do
|
6
|
+
|
7
|
+
describe "#to_date_id casts to a date id" do
|
8
|
+
|
9
|
+
describe "with fields for year, month, day #=> YYYY-MM-DD" do
|
10
|
+
|
11
|
+
it "works with string keys" do
|
12
|
+
{"year" => "2000", "month" => "12", "day" => "31"}.to_date_id.must_equal "2000-12-31"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "works with symbol keys" do
|
16
|
+
{year: "2000", month: "12", day: "31"}.to_date_id.must_equal "2000-12-31"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "without fields for year, or month, or day #=> nil" do
|
22
|
+
|
23
|
+
it "returns nil if it doesn't have a year" do
|
24
|
+
{month: "12", day: "31"}.to_date_id.must_equal nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns nil if it doesn't have a month" do
|
28
|
+
{year: "2000", day: "31"}.to_date_id.must_equal nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns nil if it doesn't have a day" do
|
32
|
+
{year: "2000", month: "12"}.to_date_id.must_equal nil
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sixarm_ruby_to_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
L2RORkllUkVIekVSClpEUlFZTXFydTlURU1uYTZIRDl6cGNzdEY3dndUaEdv
|
36
36
|
dmxPUSszWTZwbFE0bk16aXBYY1o5VEhxczY1UElMMHEKZWFid3BDYkFvcG89
|
37
37
|
Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
|
38
|
-
date: 2012-08-
|
38
|
+
date: 2012-08-22 00:00:00.000000000 Z
|
39
39
|
dependencies: []
|
40
40
|
description:
|
41
41
|
email: sixarm@sixarm.com
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/sixarm_ruby_to_id.rb
|
51
51
|
- lib/sixarm_ruby_to_id/array.rb
|
52
52
|
- lib/sixarm_ruby_to_id/date.rb
|
53
|
+
- lib/sixarm_ruby_to_id/hash.rb
|
53
54
|
- lib/sixarm_ruby_to_id/nil.rb
|
54
55
|
- lib/sixarm_ruby_to_id/numeric.rb
|
55
56
|
- lib/sixarm_ruby_to_id/object.rb
|
@@ -57,6 +58,7 @@ files:
|
|
57
58
|
- test/sixarm_ruby_to_id_test.rb
|
58
59
|
- test/sixarm_ruby_to_id_test/array_test.rb
|
59
60
|
- test/sixarm_ruby_to_id_test/date_test.rb
|
61
|
+
- test/sixarm_ruby_to_id_test/hash_test.rb
|
60
62
|
- test/sixarm_ruby_to_id_test/nil_test.rb
|
61
63
|
- test/sixarm_ruby_to_id_test/numeric_test.rb
|
62
64
|
- test/sixarm_ruby_to_id_test/object_test.rb
|
@@ -89,6 +91,7 @@ test_files:
|
|
89
91
|
- test/sixarm_ruby_to_id_test.rb
|
90
92
|
- test/sixarm_ruby_to_id_test/array_test.rb
|
91
93
|
- test/sixarm_ruby_to_id_test/date_test.rb
|
94
|
+
- test/sixarm_ruby_to_id_test/hash_test.rb
|
92
95
|
- test/sixarm_ruby_to_id_test/nil_test.rb
|
93
96
|
- test/sixarm_ruby_to_id_test/numeric_test.rb
|
94
97
|
- test/sixarm_ruby_to_id_test/object_test.rb
|
metadata.gz.sig
CHANGED