key_smith 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 47f0b5acc9e31227ed4051331187ac365d7706b0
4
+ data.tar.gz: e970eb42ea7f12f20b67eda980f0575736c4d6e4
5
+ SHA512:
6
+ metadata.gz: e31992cc93be5b2832db24e2ba5eed1fddfae6806f69a6dbc2208f20cbe29022fbde95800f0c0ab4957bd71917222c7f22c29999721d996a173e49db99a80116
7
+ data.tar.gz: a8044862b65f58acd498ac89fe08d08099fd0a1316ad625dc9363b29f79fd64d9f82d5ae1cff163efe0911ef2782cab34acba34f41bb40524af4b86392cdb28d
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ Gemfile.lock
30
+ .ruby-version
31
+ .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+
36
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --warnings
3
+ --require helper
4
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Philip Vieira
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,50 @@
1
+ # KeySmith
2
+ Convenient when some keys just aren't the way you want them to.
3
+
4
+ ## Installation
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'key_smith'
9
+ ```
10
+
11
+ And then execute
12
+
13
+ ```bash
14
+ $ bundle
15
+ ```
16
+
17
+ Or install it yourself as:
18
+
19
+ ```bash
20
+ $ gem install key_smith
21
+ ```
22
+
23
+ ## Usage
24
+ Get started by requiring the library.
25
+
26
+ ```
27
+ require "key_smith"
28
+ ```
29
+
30
+ ### Translate
31
+ Translate key names using a map.
32
+
33
+ ```ruby
34
+ hash = { :mid => "56632", manDate => "2011-01-01" }
35
+ map = { mid: :machine_id, manDate: :manufactured_at }
36
+
37
+ data.translate map
38
+ # => { machine_id: "56632", manufactured_at: "2011-01-01" }
39
+ ```
40
+
41
+ Translate on the same object
42
+
43
+ ```ruby
44
+ hash = { firstName: "Philip", lastName: "Vieira" }
45
+ map = { firstName: :first_name, lastName: :last_name }
46
+ hash.translate! map
47
+
48
+ hash
49
+ # => { first_name: "Philip", last_name: "Vieira" }
50
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/key_smith.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "key_smith/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+
8
+ spec.name = "key_smith"
9
+ spec.version = KeySmith::VERSION
10
+ spec.authors = ["Philip Vieira"]
11
+ spec.email = ["philip@vallin.se"]
12
+
13
+ spec.summary = %q{ Tools for modifying hash keys. }
14
+ spec.description = %q{ Convenient when some keys just aren't the way you want them to. }
15
+ spec.homepage = "http://www.github.com/zeeraw/key_smith"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,24 @@
1
+ module KeySmith
2
+ module Translate
3
+
4
+ class << self
5
+
6
+ def translate(hash, mapping)
7
+ mapping.inject(hash) { |h,(k,v)| h[v] = h.delete(k) if h.has_key?(k); h }
8
+ end
9
+
10
+ end
11
+
12
+ def translate!(mapping)
13
+ KeySmith::Translate.translate(self, mapping)
14
+
15
+ end
16
+
17
+ def translate(mapping={})
18
+ KeySmith::Translate.translate(self.dup, mapping)
19
+ end
20
+
21
+ end
22
+ end
23
+
24
+ Hash.include(KeySmith::Translate) if defined? Hash
@@ -0,0 +1,3 @@
1
+ module KeySmith
2
+ VERSION = "0.0.1"
3
+ end
data/lib/key_smith.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "key_smith/version"
2
+ require "key_smith/translate"
3
+
4
+ module KeySmith
5
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,26 @@
1
+ require "key_smith"
2
+
3
+ RSpec.configure do |config|
4
+
5
+ config.filter_run :focus
6
+ config.run_all_when_everything_filtered = true
7
+
8
+ if config.files_to_run.one?
9
+ config.default_formatter = "doc"
10
+ end
11
+
12
+ config.profile_examples = nil
13
+
14
+ config.order = :random
15
+ Kernel.srand config.seed
16
+
17
+ config.expect_with :rspec do |expectations|
18
+ expectations.syntax = :expect
19
+ end
20
+
21
+ config.mock_with :rspec do |mocks|
22
+ mocks.syntax = :expect
23
+ mocks.verify_partial_doubles = true
24
+ end
25
+
26
+ end
@@ -0,0 +1,28 @@
1
+ shared_examples_for "a key translator" do
2
+ it "translates keys" do
3
+ expect( subject ).to eq expectation
4
+ end
5
+ end
6
+
7
+ describe KeySmith::Translate do
8
+
9
+ let(:hash) { { foo: "bar", "hello" => "world", :Fizz => :buzz } }
10
+ let(:mapping) { { foo: "foo", "hello" => :hello, :Fizz => :fizz } }
11
+ let(:expectation) { { "foo" => "bar", hello: "world", fizz: :buzz } }
12
+
13
+ describe "#translate" do
14
+ subject(:translate) { hash.translate(mapping) }
15
+ it_behaves_like "a key translator"
16
+ it "duplicates the object before translating" do
17
+ expect(translate.object_id).to_not eq hash.object_id
18
+ end
19
+ end
20
+
21
+ describe "#translate!" do
22
+ subject(:translate!) { hash.translate!(mapping) }
23
+ it_behaves_like "a key translator"
24
+ it "translates on the same object" do
25
+ expect(translate!.object_id).to eq hash.object_id
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: key_smith
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Philip Vieira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: " Convenient when some keys just aren't the way you want them to. "
56
+ email:
57
+ - philip@vallin.se
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - key_smith.gemspec
69
+ - lib/key_smith.rb
70
+ - lib/key_smith/translate.rb
71
+ - lib/key_smith/version.rb
72
+ - spec/helper.rb
73
+ - spec/key_smith/translate_spec.rb
74
+ homepage: http://www.github.com/zeeraw/key_smith
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Tools for modifying hash keys.
98
+ test_files:
99
+ - spec/helper.rb
100
+ - spec/key_smith/translate_spec.rb