symbolizer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f41ba7fe8ccdc513ecd852c87595b87e239b2c72
4
+ data.tar.gz: dcdababd6809c771f0a7922f7a637b868e3fff32
5
+ SHA512:
6
+ metadata.gz: 5d66f75e8cee1329d90fadfd072718190d04cf5e44d46ebc9c244443f494366849127c3ad9f206319de8569cb34ebb5d8e0ad4c150341cac94998fce31a40de6
7
+ data.tar.gz: c5912418ac35ca8d1266c5c410079eefc8344f61e4e5d886d5792e919c6a558133ba8af702a83805c48fe2bf9ceb8c364fa768e5f129a2f7703da2465ca9bbd0
@@ -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
@@ -0,0 +1 @@
1
+ symbolizer
@@ -0,0 +1 @@
1
+ 2.1.0
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ before_install: gem install bundler
3
+ script: bundle exec rake ci
4
+ rvm:
5
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in symbolizer.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Indrek Juhkam
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.
@@ -0,0 +1,32 @@
1
+ # Symbolizer
2
+ [![Build Status](https://secure.travis-ci.org/salemove/symbolizer.png?branch=master)](http://travis-ci.org/salemove/symbolizer)
3
+ [![Code Climate](https://codeclimate.com/github/salemove/symbolizer.png)](https://codeclimate.com/github/salemove/symbolizer)
4
+
5
+ ```ruby
6
+ Symbolizer.symbolize({'a' => {'b' => 'c'}}) # => {a: {b: 'c'}}
7
+ ```
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'symbolizer'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ ## Contributing
20
+
21
+ 1. Fork it
22
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
23
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
24
+ 4. Push to the branch (`git push origin my-new-feature`)
25
+ 5. Create new Pull Request
26
+
27
+ ## Credits
28
+
29
+ ![SaleMove Inc. 2012][SaleMove Logo]
30
+
31
+ [SaleMove, Inc]: http://salemove.com/ "SaleMove Website"
32
+ [SaleMove Logo]: http://app.salemove.com/assets/logo.png "SaleMove Inc. 2012"
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task ci: :spec
7
+ task default: :spec
@@ -0,0 +1,31 @@
1
+ require 'symbolizer/version'
2
+
3
+ module Symbolizer
4
+ # Symbolize hash keys
5
+ #
6
+ # @example
7
+ # Symbolizer.symbolize('a' => 'b') # => {a: 'b'}
8
+ # Symbolizer.symbolize('a' => {'b' => 'c'}) # => {a: {b: 'c'}}
9
+ # # See specs for more examples
10
+ #
11
+ # @param [Hash] hash
12
+ #
13
+ # @return [Hash]
14
+ # hash with symbolized keys
15
+ #
16
+ # @api public
17
+ def self.symbolize(hash)
18
+ hash.each_with_object({}) do |(key, value), normalized_hash|
19
+ normalized_hash[key.to_sym] = normalize_value(value)
20
+ end
21
+ end
22
+
23
+ def self.normalize_value(value)
24
+ case value
25
+ when Hash then symbolize(value)
26
+ when Array then value.map(&method(:normalize_value))
27
+ else value
28
+ end
29
+ end
30
+ private_class_method :normalize_value
31
+ end
@@ -0,0 +1,3 @@
1
+ module Symbolizer
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,39 @@
1
+ require 'symbolizer'
2
+
3
+ describe Symbolizer do
4
+ describe '.symbolize' do
5
+ subject { described_class.symbolize(input) }
6
+
7
+ context 'when one level hash' do
8
+ let(:input) { {'a' => 'b'} }
9
+
10
+ it 'symbolizes keys' do
11
+ should eq(a: 'b')
12
+ end
13
+ end
14
+
15
+ context 'when nested hash' do
16
+ let(:input) { {'a' => {'b' => 'c'}} }
17
+
18
+ it 'symbolizes keys recursively' do
19
+ should eq(a: {b: 'c'})
20
+ end
21
+ end
22
+
23
+ context 'when hash in an array' do
24
+ let(:input) { {'a' => [{'b' => 'c'}]} }
25
+
26
+ it 'symbolizes keys recursively' do
27
+ should eq(a: [{b: 'c'}])
28
+ end
29
+ end
30
+
31
+ context 'when array' do
32
+ let(:input) { {'a' => [[1, 2], [3, 4]]} }
33
+
34
+ it 'symbolizes keys recursively' do
35
+ should eq(a: [[1, 2], [3, 4]])
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'symbolizer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'symbolizer'
8
+ spec.version = Symbolizer::VERSION
9
+ spec.authors = ['Indrek Juhkam', 'Urmas Talimaa']
10
+ spec.email = ['indrek@salemove.com', 'urmas@salemove.com']
11
+ spec.description = %q{Ruby hash symbolizer}
12
+ spec.summary = %q{Because activesupport is too big}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: symbolizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Indrek Juhkam
8
+ - Urmas Talimaa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: Ruby hash symbolizer
43
+ email:
44
+ - indrek@salemove.com
45
+ - urmas@salemove.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - ".ruby-gemset"
52
+ - ".ruby-version"
53
+ - ".travis.yml"
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/symbolizer.rb
59
+ - lib/symbolizer/version.rb
60
+ - spec/symbolizer_spec.rb
61
+ - symbolizer.gemspec
62
+ homepage: ''
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.0.rc.1
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Because activesupport is too big
86
+ test_files:
87
+ - spec/symbolizer_spec.rb