symbolize_all 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --backtrace
3
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in symbolize_all.gemspec
4
+ gemspec
5
+
6
+ gem 'bundler'
7
+ gem 'rspec'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 David Jairala
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # SymbolizeAll
2
+
3
+ Symbolizes everything possible in a Hash or Array.
4
+
5
+ Converts every possible key/value inside a Hash or Array into its symbolized version, recursively.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'symbolize_all'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install symbolize_all
20
+
21
+ ## Usage
22
+
23
+ > {'friend' => 'mary','enemy' => 'peter'}.symbolize_all
24
+ => {:friend=>:mary, :enemy=>:peter}
25
+
26
+ > {'friend' => 'mary','number' => 1, 5 => 10}.symbolize_all
27
+ => {:friend=>:mary, :number=>1, 5=>10}
28
+
29
+ > {'friend' => 'normal', 'nested' => {"one" => "two"}}.symbolize_all
30
+ => {:friend=>:normal, :nested=>{:one=>:two}}
31
+
32
+ More ussage examples and results can be found in `spec/symbolize_all_spec.rb`
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ module SymbolizeAll
2
+
3
+ module Array
4
+
5
+ def symbolize_all
6
+ self.map do |val|
7
+ case val.class.to_s
8
+ when 'String'
9
+ val.to_sym
10
+ when 'Array', 'Hash'
11
+ val.symbolize_all
12
+ else
13
+ val
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ Array.send :include, SymbolizeAll::Array
@@ -0,0 +1,28 @@
1
+ module SymbolizeAll
2
+
3
+ module Hash
4
+
5
+ def symbolize_all
6
+ symbolized = {}
7
+
8
+ each do |key, val|
9
+ new_key = key.is_a?(String) ? key.to_sym : key
10
+
11
+ case val.class.to_s
12
+ when 'String'
13
+ symbolized[new_key] = val.to_sym
14
+ when 'Array', 'Hash'
15
+ symbolized[new_key] = val.symbolize_all
16
+ else
17
+ symbolized[new_key] = val
18
+ end
19
+ end
20
+
21
+ symbolized
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ Hash.send :include, SymbolizeAll::Hash
@@ -0,0 +1,3 @@
1
+ module SymbolizeAll
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ require "symbolize_all/version"
2
+ require "symbolize_all/array"
3
+ require "symbolize_all/hash"
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'symbolize_all'
4
+ require 'rspec'
@@ -0,0 +1,43 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe SymbolizeAll do
4
+
5
+ describe Hash do
6
+ describe '#symbolize_all' do
7
+ [
8
+ [{'friend' => 'mary','enemy' => 'peter'}, {:friend => :mary, :enemy => :peter}],
9
+ [{'friend' => 'mary','number' => 1, 5 => 10}, {:friend => :mary, :number => 1, 5 => 10}],
10
+ [{'friend' => 'normal', 'nested' => {"one" => "two"}}, {:friend => :normal, :nested => {:one => :two}}],
11
+ [{'friend' => 'normal', 'array' => ["one", "two"]}, {:friend => :normal, :array => [:one, :two]}],
12
+ [{'string' => nil}, {:string => nil}],
13
+ [{}, {}]
14
+ ].each do |input, expected|
15
+
16
+ it "for `#{input}` expects `#{expected}`" do
17
+ input.symbolize_all.should eql expected
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+
24
+ describe Array do
25
+ describe '#symbolize_all' do
26
+ [
27
+ [['mary', 'peter'], [:mary, :peter]],
28
+ [['string', 10], [:string, 10]],
29
+ [['something', {'test' => 'hashes'}], [:something, {:test => :hashes}]],
30
+ [['friend', ['nested', 'sure']], [:friend, [:nested, :sure]]],
31
+ [['string', nil], [:string, nil]],
32
+ [[], []]
33
+ ].each do |input, expected|
34
+
35
+ it "for `#{input}` expects `#{expected}`" do
36
+ input.symbolize_all.should eql expected
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/symbolize_all/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["David Jairala"]
6
+ gem.email = ["davidjairala@gmail.com"]
7
+ gem.description = %q{Symbolizes everything possible in a Hash or Array}
8
+ gem.summary = %q{Converts every possible key/value inside a Hash or Array into its symbolized version, recursively}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "symbolize_all"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = SymbolizeAll::VERSION
17
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: symbolize_all
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - David Jairala
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-01-05 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Symbolizes everything possible in a Hash or Array
22
+ email:
23
+ - davidjairala@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - .rspec
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/symbolize_all.rb
38
+ - lib/symbolize_all/array.rb
39
+ - lib/symbolize_all/hash.rb
40
+ - lib/symbolize_all/version.rb
41
+ - spec/spec_helper.rb
42
+ - spec/symbolize_all_spec.rb
43
+ - symbolize_all.gemspec
44
+ homepage: ""
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.24
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Converts every possible key/value inside a Hash or Array into its symbolized version, recursively
77
+ test_files:
78
+ - spec/spec_helper.rb
79
+ - spec/symbolize_all_spec.rb