saneitized 1.0.1 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1aea000050c5391f959faea1399cbe08a651b86
4
- data.tar.gz: 890266370085e2fddedd0c26169bde2fadfb6d74
3
+ metadata.gz: 57797fd6f364ce22e6bc47a45c487d83d40e87cf
4
+ data.tar.gz: e9ee29462bdf3293692c1440670f8aac9decef9d
5
5
  SHA512:
6
- metadata.gz: d57de8a38f2ce61bf8c44f3a1254973b17ba842bd24f97ac98b708e5fffd5a7ed64c50a9583be9f8750ceb66cf1856441e21e38dd4104fd4891a37cb69fe8a94
7
- data.tar.gz: 94ae347a107b4c72df66f9f2a04c59ae3a0d0ba1ebb6ac643c7f97d8f9d03a171a7815f74487cafdefd27fd68021ad64cdc2c31e0f9ecc74856da0e1995bc2a6
6
+ metadata.gz: 00a3dad691343a586ed669080401b247d8c8d7e6006227cfc12f466c1410a2a2d6b6f1e079076b305243b8bf90510611e4aaf1b826a4a4f5ba50b8fd6c19571a
7
+ data.tar.gz: 98025680aa91909826b51cc3b1388cf4a5d2acc63dffa7d668530bc507501010d91750f289ed08bea5c087f4e05d152d9f20ed98a673821ca9385c196b77c851
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
- - 2.1.0
5
- - jruby-19mode
4
+ - 2.0.0
5
+ - 2.1.2
6
+ #- jruby-19mode
data/README.md CHANGED
@@ -35,6 +35,7 @@ the new value if it succeeds
35
35
  Boolean: Saneitized.convert('true') #=> true ('false' works the same way)
36
36
  Integer: Saneitized.convert('42') #=> 42
37
37
  Float: Saneitized.convert('22.2') #=> 22.2
38
+ JSON: Saneitized.convert("{\"hello\":\"goodbye\"}") #=> {"hello"=>"goodbye"}
38
39
  Time: Saneitized.convert("2014-05-28T23:15:26Z") #=> 2014-05-28 23:15:26 UTC
39
40
 
40
41
  You can checkout `lib/saneitized/converter.rb` for more information
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  module Saneitized
2
4
  def self.convert(unknown)
3
5
  return Saneitized::Hash.new(unknown) if unknown.is_a? ::Hash
@@ -8,6 +10,7 @@ module Saneitized
8
10
 
9
11
  if value = Converter.integer?(unknown) then return value end
10
12
  if value = Converter.float?(unknown) then return value end
13
+ if value = Converter.json?(unknown) then return convert(value) end
11
14
  if value = Converter.time?(unknown) then return value end
12
15
 
13
16
  unknown
@@ -15,6 +18,13 @@ module Saneitized
15
18
 
16
19
  module Converter
17
20
  extend self
21
+
22
+ def json?(unknown)
23
+ JSON.parse(unknown)
24
+ rescue JSON::ParserError, TypeError
25
+ false
26
+ end
27
+
18
28
  def integer?(unknown)
19
29
  Integer(unknown)
20
30
  rescue ArgumentError, TypeError
@@ -1,3 +1,3 @@
1
1
  module Saneitized
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
data/saneitized.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Benjamin Guest']
10
10
  spec.email = ['benguest@gmail.com']
11
11
  spec.summary = %q{Sanely converts string values to their ruby equivalent}
12
- spec.description = %q{Converts ruby hash values from strings to fixnums, floats, true and false values if it can sanely do so.}
12
+ spec.description = %q{Converts ruby values from strings to fixnums, floats, times, true and false values if it can sanely do so.}
13
13
  spec.homepage = 'https://github.com/bguest/saneitized'
14
14
  spec.license = 'MIT'
15
15
 
@@ -14,6 +14,12 @@ describe Saneitized do
14
14
  Saneitized.convert(insane).should == sane
15
15
  end
16
16
 
17
+ it 'should convert json' do
18
+ insane = {'all' => '34.2', 'base' => ['are', 'true', '10'] }.to_json
19
+ sane = {'all' => 34.2, 'base' => ['are', true, 10]}
20
+ Saneitized.convert(insane).should == sane
21
+ end
22
+
17
23
  it "should change 'true' to true" do
18
24
  Saneitized.convert('true').should == true
19
25
  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.0.1
4
+ version: 1.1.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-05-30 00:00:00.000000000 Z
11
+ date: 2014-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,8 +80,8 @@ dependencies:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.7'
83
- description: Converts ruby hash values from strings to fixnums, floats, true and false
84
- values if it can sanely do so.
83
+ description: Converts ruby values from strings to fixnums, floats, times, true and
84
+ false values if it can sanely do so.
85
85
  email:
86
86
  - benguest@gmail.com
87
87
  executables: []