saneitized 1.2.0 → 1.3.0
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/README.md +6 -0
- data/lib/saneitized/converter.rb +5 -6
- data/lib/saneitized/version.rb +1 -1
- data/spec/saneitized/converter_spec.rb +13 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7c7d693f5788a72925fc71286dbb0763beec6bb
|
4
|
+
data.tar.gz: f8af45cfe6328a8ceca644fba63b876b77a505a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e785b779cf22c52d537d00eed01ce80b38303da62a511d323fbe5d7cbe6af87184f4f9419aaa7c30475612afa7dc2d9291910192b956f78655b47b3eeac762b
|
7
|
+
data.tar.gz: 78039489fec19a1f3ac16562e20894d2602f1ecc4c3e0ef3acf3814ce3b5094c81eca7016dd0a0ed22d220503b94b85c758dd74cb671cfa3c986a07f3a4d2887
|
data/README.md
CHANGED
@@ -58,6 +58,12 @@ as regular arrays except that new assigned values will also be saneitized
|
|
58
58
|
hash['fred'] = '234'
|
59
59
|
hash['fred'] #=> 234
|
60
60
|
|
61
|
+
### Blacklists
|
62
|
+
|
63
|
+
You can make sanitized ignore certain strings by includeing a blacklist option
|
64
|
+
|
65
|
+
Sanitized.convert('23', blacklist:%w(21 22 23)) => '23'
|
66
|
+
|
61
67
|
### Important Notes
|
62
68
|
|
63
69
|
To convert a sanetized array/hash back to a non-saneitized hash, simply call the #to_a and #to_h
|
data/lib/saneitized/converter.rb
CHANGED
@@ -2,10 +2,13 @@ require 'json'
|
|
2
2
|
require 'chronic'
|
3
3
|
|
4
4
|
module Saneitized
|
5
|
-
|
5
|
+
|
6
|
+
def self.convert(unknown, options = {})
|
7
|
+
options[:blacklist] ||= nil
|
6
8
|
return Saneitized::Hash.new(unknown) if unknown.is_a? ::Hash
|
7
9
|
return Saneitized::Array.new(unknown) if unknown.is_a? ::Array
|
8
10
|
return unknown unless unknown.is_a? String #Only attempt to convert string
|
11
|
+
return unknown if Array(options[:blacklist]).include?(unknown)
|
9
12
|
|
10
13
|
%w(true false nil integer float json time).each do |type|
|
11
14
|
value = Converter.send(type + '?', unknown)
|
@@ -13,14 +16,10 @@ module Saneitized
|
|
13
16
|
return (type == 'json') ? convert(value) : value
|
14
17
|
end
|
15
18
|
|
16
|
-
#if value = Converter.integer?(unknown) then return value end
|
17
|
-
#if value = Converter.float?(unknown) then return value end
|
18
|
-
#if (value = Converter.json?(unknown)) != :nope then return convert(value) end
|
19
|
-
#if value = Converter.time?(unknown) then return value end
|
20
|
-
|
21
19
|
unknown
|
22
20
|
end
|
23
21
|
|
22
|
+
|
24
23
|
module Converter
|
25
24
|
extend self
|
26
25
|
|
data/lib/saneitized/version.rb
CHANGED
@@ -62,8 +62,19 @@ describe Saneitized do
|
|
62
62
|
expect(Saneitized.convert("2001-02-03 10:11:12 -0400")).to eql Time.new(2001,2,3,10,11,12,'-04:00')
|
63
63
|
end
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
%w(marketplaces).each do |string|
|
66
|
+
it "should leave #{string} alone" do
|
67
|
+
expect(Saneitized.convert(string)).to eq string
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should respect blacklist' do
|
72
|
+
expect(Saneitized.convert('day', blacklist:'day')).to eql 'day'
|
67
73
|
end
|
74
|
+
|
75
|
+
it 'should respect array blacklist' do
|
76
|
+
expect(Saneitized.convert('day', blacklist:%w(hour day))).to eql 'day'
|
77
|
+
end
|
78
|
+
|
68
79
|
end
|
69
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saneitized
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Guest
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chronic
|