sixarm_ruby_to_id 1.0.4
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/.gemtest +0 -0
- data/README.md +93 -0
- data/Rakefile +8 -0
- data/VERSION +1 -0
- data/lib/sixarm_ruby_to_id/array.rb +62 -0
- data/lib/sixarm_ruby_to_id/date.rb +14 -0
- data/lib/sixarm_ruby_to_id/nil.rb +61 -0
- data/lib/sixarm_ruby_to_id/numeric.rb +15 -0
- data/lib/sixarm_ruby_to_id/object.rb +10 -0
- data/lib/sixarm_ruby_to_id/string.rb +114 -0
- data/lib/sixarm_ruby_to_id.rb +8 -0
- data/test/sixarm_ruby_to_id_test/array_test.rb +41 -0
- data/test/sixarm_ruby_to_id_test/date_test.rb +14 -0
- data/test/sixarm_ruby_to_id_test/nil_test.rb +55 -0
- data/test/sixarm_ruby_to_id_test/numeric_test.rb +19 -0
- data/test/sixarm_ruby_to_id_test/object_test.rb +21 -0
- data/test/sixarm_ruby_to_id_test/string_test.rb +79 -0
- data/test/sixarm_ruby_to_id_test.rb +10 -0
- data.tar.gz.sig +0 -0
- metadata +96 -0
- metadata.gz.sig +4 -0
data/.gemtest
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# SixArm.com » Ruby » <br> ToId gem
|
2
|
+
|
3
|
+
* Doc: <http://sixarm.com/sixarm_ruby_to_id/doc>
|
4
|
+
* Gem: <http://rubygems.org/gems/sixarm_ruby_to_id>
|
5
|
+
* Repo: <http://github.com/sixarm/sixarm_ruby_to_id>
|
6
|
+
* Email: Joel Parker Henderson, <joel@sixarm.com>
|
7
|
+
|
8
|
+
## Introduction
|
9
|
+
|
10
|
+
Convert strings to various kinds of id types and uuid types.
|
11
|
+
|
12
|
+
For docs go to <http://sixarm.com/sixarm_ruby_to_id/doc>
|
13
|
+
|
14
|
+
We use this gem to help santize web application inputs, for example HTTP query strings and form input controls.
|
15
|
+
|
16
|
+
Want to help? We're happy to get pull requests.
|
17
|
+
|
18
|
+
|
19
|
+
## Install quickstart
|
20
|
+
|
21
|
+
Install:
|
22
|
+
|
23
|
+
gem install sixarm_ruby_to_id
|
24
|
+
|
25
|
+
Bundler:
|
26
|
+
|
27
|
+
gem "sixarm_ruby_to_id", "~>1.0.0"
|
28
|
+
|
29
|
+
Require:
|
30
|
+
|
31
|
+
require "sixarm_ruby_to_id"
|
32
|
+
|
33
|
+
|
34
|
+
## Install with security (optional)
|
35
|
+
|
36
|
+
To enable high security for all our gems:
|
37
|
+
|
38
|
+
wget http://sixarm.com/sixarm.pem
|
39
|
+
gem cert --add sixarm.pem
|
40
|
+
gem sources --add http://sixarm.com
|
41
|
+
|
42
|
+
To install with high security:
|
43
|
+
|
44
|
+
gem install sixarm_ruby_to_id --test --trust-policy HighSecurity
|
45
|
+
|
46
|
+
|
47
|
+
## Examples
|
48
|
+
|
49
|
+
Cast a string to an integer id:
|
50
|
+
|
51
|
+
"100".to_i_id #=> 100
|
52
|
+
|
53
|
+
Cast a string to a string UUID and ensure it has the right hex characters and dash locations:
|
54
|
+
|
55
|
+
"bbd98640-4c2a-4343-ab6b-0ebd2fec6362".to_uuid
|
56
|
+
|
57
|
+
Cast a comma-separated list to string ids:
|
58
|
+
|
59
|
+
"a,b,c".to_s_ids #=> ["a", "b", "c"]
|
60
|
+
|
61
|
+
|
62
|
+
## Changes
|
63
|
+
|
64
|
+
* 2012-08-11 1.0.0 Publish
|
65
|
+
|
66
|
+
|
67
|
+
## License
|
68
|
+
|
69
|
+
You may choose any of these open source licenses:
|
70
|
+
|
71
|
+
* Apache License
|
72
|
+
* BSD License
|
73
|
+
* CreativeCommons License, Non-commercial Share Alike
|
74
|
+
* GNU General Public License Version 2 (GPL 2)
|
75
|
+
* GNU Lesser General Public License (LGPL)
|
76
|
+
* MIT License
|
77
|
+
* Perl Artistic License
|
78
|
+
* Ruby License
|
79
|
+
|
80
|
+
The software is provided "as is", without warranty of any kind,
|
81
|
+
express or implied, including but not limited to the warranties of
|
82
|
+
merchantability, fitness for a particular purpose and noninfringement.
|
83
|
+
|
84
|
+
In no event shall the authors or copyright holders be liable for any
|
85
|
+
claim, damages or other liability, whether in an action of contract,
|
86
|
+
tort or otherwise, arising from, out of or in connection with the
|
87
|
+
software or the use or other dealings in the software.
|
88
|
+
|
89
|
+
This license is for the included software that is created by SixArm;
|
90
|
+
some of the included software may have its own licenses, copyrights,
|
91
|
+
authors, etc. and these do take precedence over the SixArm license.
|
92
|
+
|
93
|
+
Copyright (c) 2005-2013 Joel Parker Henderson
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class Array
|
2
|
+
|
3
|
+
|
4
|
+
# Cast the items to date ids.
|
5
|
+
#
|
6
|
+
# "2000-12-31,2001-12-31,2002-12-31".to_date_id
|
7
|
+
# #=> ["2000-12-31", "2001-12-31", "2002-12-13"]
|
8
|
+
#
|
9
|
+
def to_date_ids
|
10
|
+
map{|x| x.to_date_id}
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
# Cast the items to stint ids.
|
15
|
+
#
|
16
|
+
# ["2000-12-30-2000-12-31", "2001-12-30-2001-12-31", "2002-12-30-2002-12-31".to_stint_ids
|
17
|
+
# #=> ["2000-12-30-2000-12-31", "2001-12-30-2001-12-31", "2002-12-30-2002-12-31"]
|
18
|
+
#
|
19
|
+
def to_stint_ids
|
20
|
+
map{|x| x.to_stint_id}
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# Cast the items to integer ids.
|
25
|
+
#
|
26
|
+
# [" 1 ", " 2 ", " 3 "].to_i_ids
|
27
|
+
# #=> [1, 2, 3]
|
28
|
+
#
|
29
|
+
def to_i_ids
|
30
|
+
map{|x| x.to_i_id}
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
# Cast the items to string ids.
|
35
|
+
#
|
36
|
+
# [" a ", " b ", " c "].to_i_ids
|
37
|
+
# #=> ["a", "b", "c"]
|
38
|
+
#
|
39
|
+
def to_s_ids
|
40
|
+
map{|x| x.to_s_id}
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# Cast the items to string uuids.
|
45
|
+
#
|
46
|
+
# [
|
47
|
+
# " 00000000-0000-0000-0000-000000000000 "
|
48
|
+
# " 11111111-1111-1111-1111-111111111111 ",
|
49
|
+
# " 22222222-2222-2222-2222-222222222222 "
|
50
|
+
# ].to_s_uuids
|
51
|
+
# #=> [
|
52
|
+
# "00000000-0000-0000-0000-000000000000"
|
53
|
+
# "11111111-1111-1111-1111-111111111111",
|
54
|
+
# "22222222-2222-2222-2222-222222222222"
|
55
|
+
# ]
|
56
|
+
#
|
57
|
+
def to_s_uuids
|
58
|
+
map{|x| x.to_s_uuid}
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class NilClass
|
2
|
+
|
3
|
+
|
4
|
+
# Always return nil.
|
5
|
+
#
|
6
|
+
def to_date_id
|
7
|
+
nil
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
# Always return nil.
|
12
|
+
#
|
13
|
+
def to_date_ids
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
# Always return nil.
|
19
|
+
#
|
20
|
+
def to_stint_id
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
# Always return nil.
|
26
|
+
#
|
27
|
+
def to_stint_ids
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# Always return nil.
|
33
|
+
#
|
34
|
+
def to_i_id
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
# Always return nil.
|
40
|
+
#
|
41
|
+
def to_i_ids
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
# Always return nil.
|
47
|
+
#
|
48
|
+
def to_s_id
|
49
|
+
nil
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
# Always return nil.
|
54
|
+
#
|
55
|
+
def to_s_ids
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,114 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
|
4
|
+
# Cast me to a date id.
|
5
|
+
#
|
6
|
+
# " 2000-12-31 ".to_date_id
|
7
|
+
# #=> "2000-12-31"
|
8
|
+
#
|
9
|
+
def to_date_id
|
10
|
+
s = self.strip
|
11
|
+
s =~ /\A\d\d\d\d-\d\d-\d\d\z/ ? s : nil
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
# Cast me to a list of date ids.
|
16
|
+
# The string is comma-separated.
|
17
|
+
#
|
18
|
+
# "2000-12-31,2001-12-31,2002-12-31".to_date_id
|
19
|
+
# #=> ["2000-12-31", "2001-12-31", "2002-12-31"]
|
20
|
+
#
|
21
|
+
def to_date_ids
|
22
|
+
split(/,/).map{|x| x.to_date_id}
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
# Cast me to a stint id.
|
27
|
+
#
|
28
|
+
# " 2000-12-30-2000-12-31".to_stint_id
|
29
|
+
# #=> "2000-12-30-2000-12-31"
|
30
|
+
#
|
31
|
+
def to_stint_id
|
32
|
+
s = self.strip
|
33
|
+
s =~ /\A\d\d\d\d-\d\d-\d\d-\d\d\d\d-\d\d-\d\d\z/ ? s : nil
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# Cast me to a list of stint ids.
|
38
|
+
# The string is comma-separated.
|
39
|
+
#
|
40
|
+
# "2000-12-30-2000-12-31,2001-12-30-2001-12-31,2002-12-30-2002-12-31".to_date_id
|
41
|
+
# #=> ["2000-12-30-2000-12-31"], ["2001-12-30-2001-12-31"], ["2002-12-30-2002-12-31"]]
|
42
|
+
#
|
43
|
+
def to_stint_ids
|
44
|
+
split(/,/).map{|x| x.to_stint_id}
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
# Cast me to an integer id.
|
49
|
+
#
|
50
|
+
# " 1 ".to_i_id
|
51
|
+
# #=> 1
|
52
|
+
#
|
53
|
+
def to_i_id
|
54
|
+
strip.to_i
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
# Cast me (a comma-separated list) to a list of integer ids.
|
59
|
+
# The string is comma-separated.
|
60
|
+
#
|
61
|
+
# "1,2,3".to_s_ids
|
62
|
+
# #=> [1, 2, 3]
|
63
|
+
#
|
64
|
+
def to_i_ids
|
65
|
+
split(/,/).map{|x| x.to_i_id}
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
# Cast me to a string id.
|
70
|
+
#
|
71
|
+
# " a "
|
72
|
+
# #=> "a"
|
73
|
+
#
|
74
|
+
def to_s_id
|
75
|
+
strip
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
# Cast me to a list of string ids.
|
80
|
+
# The string is comma-separated.
|
81
|
+
#
|
82
|
+
# "a,b,c".to_s_ids
|
83
|
+
# #=> ["a", "b", "c"]
|
84
|
+
#
|
85
|
+
def to_s_ids
|
86
|
+
split(/,/).to_s_ids
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# Cast me to a string uuid.
|
91
|
+
#
|
92
|
+
# " 00000000-0000-0000-0000-000000000000 ".to_s_uuids
|
93
|
+
# #=> "00000000-0000-0000-0000-000000000000"
|
94
|
+
#
|
95
|
+
def to_s_uuid
|
96
|
+
strip.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/) ? $& : nil
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
# Cast me to a list of string ids.
|
101
|
+
# The string is comma-separated.
|
102
|
+
#
|
103
|
+
# "00000000-0000-0000-0000-000000000000,11111111-1111-1111-1111-111111111111".to_s_uuids
|
104
|
+
# #=> [
|
105
|
+
# "00000000-0000-0000-0000-000000000000"
|
106
|
+
# "11111111-1111-1111-1111-111111111111"
|
107
|
+
# ]
|
108
|
+
#
|
109
|
+
def to_s_uuids
|
110
|
+
split(/,/).to_s_uuids
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'sixarm_ruby_to_id'
|
4
|
+
|
5
|
+
describe Array do
|
6
|
+
|
7
|
+
describe "#to_date_ids" do
|
8
|
+
it "casts the items to date ids" do
|
9
|
+
[" 2000-12-31 ", " 2001-12-31 ", " 2002-12-31 "].to_date_ids.must_equal ["2000-12-31", "2001-12-31", "2002-12-31"]
|
10
|
+
[" X000-12-31 ", " Y001-12-31 ", " Z002-12-31 "].to_date_ids.must_equal [nil, nil, nil]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#to_stint_ids" do
|
15
|
+
it "casts the items to stint ids" do
|
16
|
+
[" 2000-12-30-2000-12-31 ", " 2001-12-30-2001-12-31 ", " 2002-12-30-2002-12-31 "].to_stint_ids.must_equal ["2000-12-30-2000-12-31", "2001-12-30-2001-12-31", "2002-12-30-2002-12-31"]
|
17
|
+
[" X000-12-30-2000-12-31 ", " Y001-12-30-2001-12-31 ", " Z002-12-30-2002-12-31 "].to_stint_ids.must_equal [nil, nil, nil]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#to_i_ids" do
|
22
|
+
it "casts the items to integer ids" do
|
23
|
+
[" 1 ", " 2 ", " 3 "].to_i_ids.must_equal [1, 2, 3]
|
24
|
+
[" X ", " Y ", " Z "].to_i_ids.must_equal [0, 0, 0]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#to_s_ids" do
|
29
|
+
it "casts the items to string ids" do
|
30
|
+
[" 1 ", " 2 ", " 3 "].to_s_ids.must_equal ["1", "2", "3"]
|
31
|
+
[" X ", " Y ", " Z "].to_s_ids.must_equal ["X", "Y", "Z"]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#to_s_uuids" do
|
36
|
+
it "casts the items to string uuids" do
|
37
|
+
[" 0000aaaa-00aa-00aa-00aa-000000aaaaaa ", " 1111bbbb-11bb-11bb-11bb-111111bbbbbb ", " 2222cccc-22cc-22cc-22cc-222222cccccc "].to_s_uuids.must_equal ["0000aaaa-00aa-00aa-00aa-000000aaaaaa", "1111bbbb-11bb-11bb-11bb-111111bbbbbb", "2222cccc-22cc-22cc-22cc-222222cccccc"]
|
38
|
+
[" X ", " Y ", " Z "].to_s_uuids.must_equal [nil, nil, nil]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'sixarm_ruby_to_id'
|
4
|
+
|
5
|
+
describe Date do
|
6
|
+
|
7
|
+
describe "#to_date_id" do
|
8
|
+
it "casts to a date id YYYY-MM-DD" do
|
9
|
+
Date.parse("2000-12-31").to_date_id.must_equal "2000-12-31"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'sixarm_ruby_to_id'
|
4
|
+
|
5
|
+
describe NilClass do
|
6
|
+
|
7
|
+
describe "#to_date_id" do
|
8
|
+
it "always returns nil" do
|
9
|
+
nil.to_date_id.must_be_same_as nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#to_date_ids" do
|
14
|
+
it "always returns nil" do
|
15
|
+
nil.to_date_ids.must_be_same_as nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#to_stint_id" do
|
20
|
+
it "always returns nil" do
|
21
|
+
nil.to_stint_id.must_be_same_as nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#to_stint_ids" do
|
26
|
+
it "always returns nil" do
|
27
|
+
nil.to_stint_ids.must_be_same_as nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#to_i_id" do
|
32
|
+
it "always returns nil" do
|
33
|
+
nil.to_i_id.must_be_same_as nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#to_i_ids" do
|
38
|
+
it "always returns nil" do
|
39
|
+
nil.to_i_ids.must_be_same_as nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#to_s_id" do
|
44
|
+
it "always returns nil" do
|
45
|
+
nil.to_s_id.must_be_same_as nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#to_s_ids" do
|
50
|
+
it "always returns nil" do
|
51
|
+
nil.to_s_ids.must_be_same_as nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'sixarm_ruby_to_id'
|
4
|
+
|
5
|
+
describe Numeric do
|
6
|
+
|
7
|
+
describe "#to_i_id" do
|
8
|
+
it "casts me to an int id" do
|
9
|
+
1.to_i_id.must_equal 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#to_i_ids" do
|
14
|
+
it "casts me to a list of int id" do
|
15
|
+
1.to_i_ids.must_equal [1]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'sixarm_ruby_to_id'
|
4
|
+
|
5
|
+
class Mock
|
6
|
+
def id
|
7
|
+
"123"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Object do
|
12
|
+
|
13
|
+
describe "#to_i_id" do
|
14
|
+
it "returns #id.to_i" do
|
15
|
+
x = Mock.new
|
16
|
+
x.to_i_id.must_equal 123
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'sixarm_ruby_to_id'
|
4
|
+
|
5
|
+
describe String do
|
6
|
+
|
7
|
+
describe "#to_date_id" do
|
8
|
+
it "casts me to a date id YYYY-MM-DD" do
|
9
|
+
" 2000-12-31 ".to_date_id.must_equal "2000-12-31"
|
10
|
+
" X000-12-31 ".to_date_id.must_equal nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#to_date_ids" do
|
15
|
+
it "casts me to a list of date ids" do
|
16
|
+
" 2000-12-31 , 2001-12-31 , 2002-12-31 ".to_date_ids.must_equal ["2000-12-31", "2001-12-31", "2002-12-31"]
|
17
|
+
" X000-12-31 , Y001-12-31 , Z002-12-31 ".to_date_ids.must_equal [nil, nil, nil]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#to_stint_id" do
|
22
|
+
it "casts me to a stint id [YYYY-MM-DD, YYYY-MM-DD]" do
|
23
|
+
" 2000-12-30-2000-12-31 ".to_stint_id.must_equal "2000-12-30-2000-12-31"
|
24
|
+
" X000-12-30-2000-12-31 ".to_stint_id.must_equal nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#to_stint_ids" do
|
29
|
+
it "casts me to a list of stint ids" do
|
30
|
+
" 2000-12-30-2000-12-31 , 2001-12-30-2001-12-31 , 2002-12-30-2002-12-31 ".to_stint_ids.must_equal ["2000-12-30-2000-12-31", "2001-12-30-2001-12-31", "2002-12-30-2002-12-31"]
|
31
|
+
" X000-12-30-2000-12-31 , Y001-12-30-2001-12-31 , Z002-12-30-2002-12-31 ".to_stint_ids.must_equal [nil, nil, nil]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#to_i_id" do
|
36
|
+
it "casts me to an integer id (by using strip and to_i)" do
|
37
|
+
" 1 ".to_i_id.must_equal 1
|
38
|
+
" X ".to_i_id.must_equal 0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#to_i_ids" do
|
43
|
+
it "casts me (a comma-separated list of items) to a list of integer ids (by using strip and to_i)" do
|
44
|
+
" 1 , 2 , 3".to_i_ids.must_equal [1, 2, 3]
|
45
|
+
" X , Y , Z".to_i_ids.must_equal [0, 0, 0]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#to_s_id" do
|
50
|
+
it "casts me to a string id (by using strip)" do
|
51
|
+
" 1 ".to_s_id.must_equal "1"
|
52
|
+
" X ".to_s_id.must_equal "X"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#to_s_ids" do
|
57
|
+
it "casts me (a comma-separated list of items) to a list of string ids (by using strip and to_i)" do
|
58
|
+
" 1 , 2 , 3".to_s_ids.must_equal ["1", "2", "3"]
|
59
|
+
" X , Y , Z".to_s_ids.must_equal ["X", "Y", "Z"]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#to_s_uuid" do
|
64
|
+
it "casts me to a string uuid (by using strip and match)" do
|
65
|
+
" 0000aaaa-00aa-00aa-00aa-000000aaaaaa ".to_s_uuid.must_equal "0000aaaa-00aa-00aa-00aa-000000aaaaaa"
|
66
|
+
" X ".to_s_uuid.must_equal nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#to_s_uuids" do
|
71
|
+
it "casts me (a comma-separated list of items) to a list of string uuids (by using split and to_s_uuid)" do
|
72
|
+
" 0000aaaa-00aa-00aa-00aa-000000aaaaaa , 1111bbbb-11bb-11bb-11bb-111111bbbbbb , 2222cccc-22cc-22cc-22cc-222222cccccc".to_s_uuids.must_equal ["0000aaaa-00aa-00aa-00aa-000000aaaaaa", "1111bbbb-11bb-11bb-11bb-111111bbbbbb", "2222cccc-22cc-22cc-22cc-222222cccccc"]
|
73
|
+
" X , Y , Z".to_s_uuids.must_equal [nil, nil, nil]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sixarm_ruby_to_id
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- SixArm
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain:
|
12
|
+
- !binary |-
|
13
|
+
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCRENDQW0yZ0F3SUJB
|
14
|
+
Z0lKQUtQd0VFVFU1YkhvTUEwR0NTcUdTSWIzRFFFQkJRVUFNR0F4Q3pBSkJn
|
15
|
+
TlYKQkFZVEFsVlRNUk13RVFZRFZRUUlFd3BEWVd4cFptOXlibWxoTVJZd0ZB
|
16
|
+
WURWUVFIRXcxVFlXNGdSbkpoYm1OcApjMk52TVE4d0RRWURWUVFLRXdaVGFY
|
17
|
+
aEJjbTB4RXpBUkJnTlZCQU1UQ25OcGVHRnliUzVqYjIwd0hoY05NVEF4Ck1q
|
18
|
+
RXpNak15TnpFeldoY05NVE13T1RBNE1qTXlOekV6V2pCZ01Rc3dDUVlEVlFR
|
19
|
+
R0V3SlZVekVUTUJFR0ExVUUKQ0JNS1EyRnNhV1p2Y201cFlURVdNQlFHQTFV
|
20
|
+
RUJ4TU5VMkZ1SUVaeVlXNWphWE5qYnpFUE1BMEdBMVVFQ2hNRwpVMmw0UVhK
|
21
|
+
dE1STXdFUVlEVlFRREV3cHphWGhoY20wdVkyOXRNSUdmTUEwR0NTcUdTSWIz
|
22
|
+
RFFFQkFRVUFBNEdOCkFEQ0JpUUtCZ1FDOTRtRDlKRHdCc3Vuc09JMFZSM0NY
|
23
|
+
WGJPV2c5Y1dhV2Npd0Z5Sk5GaU03QTlJOEtQTGZYVXcKUUM0Y3pVZTVadUc0
|
24
|
+
V0h2aW5yV2hrckNLKzFkV0Jxb0VDbHhkRi9Gb0tPNWErdG9uR0Nqam1meTgx
|
25
|
+
Sm1Gamp5eAplVHNqc0h5dncrUWlrOWtwZjlhajYrcG5rTnJWc3dnTkhWZWEy
|
26
|
+
bzl5YWJiRWlTNlZTZUpXb1FJREFRQUJvNEhGCk1JSENNQjBHQTFVZERnUVdC
|
27
|
+
QlF6UEp0cW1TZ2M1M2VETjdhU3pEUXdyOVRBTERDQmtnWURWUjBqQklHS01J
|
28
|
+
R0gKZ0JRelBKdHFtU2djNTNlRE43YVN6RFF3cjlUQUxLRmtwR0l3WURFTE1B
|
29
|
+
a0dBMVVFQmhNQ1ZWTXhFekFSQmdOVgpCQWdUQ2tOaGJHbG1iM0p1YVdFeEZq
|
30
|
+
QVVCZ05WQkFjVERWTmhiaUJHY21GdVkybHpZMjh4RHpBTkJnTlZCQW9UCkJs
|
31
|
+
TnBlRUZ5YlRFVE1CRUdBMVVFQXhNS2MybDRZWEp0TG1OdmJZSUpBS1B3RUVU
|
32
|
+
VTViSG9NQXdHQTFVZEV3UUYKTUFNQkFmOHdEUVlKS29aSWh2Y05BUUVGQlFB
|
33
|
+
RGdZRUFvb0VleFAvb1BhbTFUUDcxU3l1aHhNYit1VHJaYlNRZQpqVkIrRXhS
|
34
|
+
d1dhZEd3YU5QVUE1NmQzOXF3YXZ3UCtpdSszSnBlb25OTVZ2YldYRjVuYUNY
|
35
|
+
L2RORkllUkVIekVSClpEUlFZTXFydTlURU1uYTZIRDl6cGNzdEY3dndUaEdv
|
36
|
+
dmxPUSszWTZwbFE0bk16aXBYY1o5VEhxczY1UElMMHEKZWFid3BDYkFvcG89
|
37
|
+
Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
|
38
|
+
date: 2012-08-12 00:00:00.000000000 Z
|
39
|
+
dependencies: []
|
40
|
+
description:
|
41
|
+
email: sixarm@sixarm.com
|
42
|
+
executables: []
|
43
|
+
extensions: []
|
44
|
+
extra_rdoc_files: []
|
45
|
+
files:
|
46
|
+
- .gemtest
|
47
|
+
- Rakefile
|
48
|
+
- README.md
|
49
|
+
- VERSION
|
50
|
+
- lib/sixarm_ruby_to_id.rb
|
51
|
+
- lib/sixarm_ruby_to_id/array.rb
|
52
|
+
- lib/sixarm_ruby_to_id/date.rb
|
53
|
+
- lib/sixarm_ruby_to_id/nil.rb
|
54
|
+
- lib/sixarm_ruby_to_id/numeric.rb
|
55
|
+
- lib/sixarm_ruby_to_id/object.rb
|
56
|
+
- lib/sixarm_ruby_to_id/string.rb
|
57
|
+
- test/sixarm_ruby_to_id_test.rb
|
58
|
+
- test/sixarm_ruby_to_id_test/array_test.rb
|
59
|
+
- test/sixarm_ruby_to_id_test/date_test.rb
|
60
|
+
- test/sixarm_ruby_to_id_test/nil_test.rb
|
61
|
+
- test/sixarm_ruby_to_id_test/numeric_test.rb
|
62
|
+
- test/sixarm_ruby_to_id_test/object_test.rb
|
63
|
+
- test/sixarm_ruby_to_id_test/string_test.rb
|
64
|
+
homepage: http://sixarm.com/
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.23
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: SixArm.com » Ruby » ToId converts types to ids and uuids
|
88
|
+
test_files:
|
89
|
+
- test/sixarm_ruby_to_id_test.rb
|
90
|
+
- test/sixarm_ruby_to_id_test/array_test.rb
|
91
|
+
- test/sixarm_ruby_to_id_test/date_test.rb
|
92
|
+
- test/sixarm_ruby_to_id_test/nil_test.rb
|
93
|
+
- test/sixarm_ruby_to_id_test/numeric_test.rb
|
94
|
+
- test/sixarm_ruby_to_id_test/object_test.rb
|
95
|
+
- test/sixarm_ruby_to_id_test/string_test.rb
|
96
|
+
has_rdoc: true
|
metadata.gz.sig
ADDED