type-humanizer 0.0.5 → 0.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.
- checksums.yaml +4 -4
- data/lib/humanizer/version.rb +1 -1
- data/lib/humanizer.rb +4 -0
- data/test/sanitize_test.rb +5 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95fb6483b07c584b7b2ecfe0b3415d8eeacf853e
|
4
|
+
data.tar.gz: 8ca66071e123187dbb06e2433c82652e94ba16f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfea1608bdbbe55b68b10e6b386adf506ee2ae503acfa820bc15961aabc12138cb970e23697e76eb056c72e4da584781eedea2e27cfa224ac1257f721213a8ba
|
7
|
+
data.tar.gz: d473a020e0f0b968a23974c8dfe00b1cb382d2a6e3914a068d2257cb15746267fa2fe38badd9bd4f8d031c03f4c9af4d6914cd78157d500f0bb0324139046830
|
data/lib/humanizer/version.rb
CHANGED
data/lib/humanizer.rb
CHANGED
@@ -5,6 +5,8 @@ module Humanizer
|
|
5
5
|
def to_array(value)
|
6
6
|
value = String(value)
|
7
7
|
|
8
|
+
return nil if value.empty?
|
9
|
+
|
8
10
|
array = String(value).split ','
|
9
11
|
array.map &:strip
|
10
12
|
end
|
@@ -12,6 +14,8 @@ module Humanizer
|
|
12
14
|
def to_hash(value)
|
13
15
|
value = String(value)
|
14
16
|
hash = {}
|
17
|
+
|
18
|
+
return nil if value.empty?
|
15
19
|
|
16
20
|
value.split(',').each do |key_val|
|
17
21
|
k, v = key_val.split(':')
|
data/test/sanitize_test.rb
CHANGED
@@ -6,14 +6,17 @@ class SanitizeTest < Test::Unit::TestCase
|
|
6
6
|
sanitizer = Humanizer::Sanitize.new
|
7
7
|
|
8
8
|
assert_equal ['a', 'b', 'c'], sanitizer.to_array('a, b, c')
|
9
|
-
assert_equal [], sanitizer.to_array(
|
9
|
+
assert_equal ['a'], sanitizer.to_array('a')
|
10
|
+
assert_equal nil, sanitizer.to_array('')
|
11
|
+
assert_equal nil, sanitizer.to_array(nil)
|
10
12
|
end
|
11
13
|
|
12
14
|
def test_sanitize_hash
|
13
15
|
sanitizer = Humanizer::Sanitize.new
|
14
16
|
|
15
17
|
assert_equal({ 'foo' => 'bar', 'boo' => 'baz' }, sanitizer.to_hash('foo: bar, boo: baz'))
|
16
|
-
assert_equal(
|
18
|
+
assert_equal(nil, sanitizer.to_hash(''))
|
19
|
+
assert_equal(nil, sanitizer.to_hash(nil))
|
17
20
|
end
|
18
21
|
|
19
22
|
def test_sanitize_params
|