hash_transform 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: 71be264aab7f65fcc9623934359b1f91bae1ac5d
4
+ data.tar.gz: 2c388ef9ed8d608a3b78ad52dab80f5b7fdacbf2
5
+ SHA512:
6
+ metadata.gz: b9dda736def7600ac841f4a8eee44aff6a72fe9f7c58c6091584fb2508d99ebe42ede9158fcedd4e0f47796e0e5dacca373227f35a57c93588009005b2eb17b3
7
+ data.tar.gz: 6920cdf10c86c07e2c4b7fc287f7cd22568cef3ac11a6bb4e5170d0a94aad290fa059a23edc6b3354fa44389ef932ca5a0818140a547a68492f5db9260d32969
@@ -0,0 +1,5 @@
1
+ .idea
2
+ .ruby-version
3
+ .ruby-gemset
4
+ *.gem
5
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright © 2013 Ferenczy Péter <ggpeti@gmail.com>
2
+ This work is free. You can redistribute it and/or modify it under the
3
+ terms of the Do What The Fuck You Want To Public License, Version 2,
4
+ as published by Sam Hocevar. See below for more details.
5
+
6
+
7
+
8
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
9
+ Version 2, December 2004
10
+
11
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
12
+
13
+ Everyone is permitted to copy and distribute verbatim or modified
14
+ copies of this license document, and changing it is allowed as long
15
+ as the name is changed.
16
+
17
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
18
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
19
+
20
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
@@ -0,0 +1,29 @@
1
+ # HashTransform
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hash_transform'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hash_transform
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hash_transform/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "hash_transform"
8
+ gem.version = HashTransform::VERSION
9
+ gem.authors = ["Ferenczy Péter"]
10
+ gem.email = ["ggpeti@gmail.com"]
11
+ gem.description = %q{Use this gem to extend the Hash class with useful key and value mapping methods.}
12
+ gem.summary = %q{This gem adds map_keys, map_keys!, map_values, map_values! methods to the Hash class.}
13
+ gem.homepage = ""
14
+ gem.license = "WTFPL"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency "bundler", "~> 1.3"
22
+ gem.add_development_dependency "rake"
23
+ gem.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,79 @@
1
+ require 'hash_transform'
2
+
3
+ describe Hash do
4
+
5
+ describe "#map_keys" do
6
+
7
+ it "should return with a new Hash whose keys are mapped with the given block" do
8
+ result = { key1: "value1" }.map_keys { |key| "#{key}_mapped".to_sym }
9
+ expect(result).to eq(key1_mapped: "value1")
10
+ end
11
+
12
+
13
+
14
+ it "should not change the original hash" do
15
+ hash = { key1: "value1" }
16
+ hash.map_keys { |key| "#{key}_mapped".to_sym }
17
+ expect(hash).to eq(key1: "value1")
18
+ end
19
+
20
+ end
21
+
22
+
23
+
24
+ describe "#map_keys!" do
25
+
26
+ it "should return with a Hash whose keys are mapped with the given block" do
27
+ result = { key1: "value1" }.map_keys! { |key| "#{key}_mapped".to_sym }
28
+ expect(result).to eq(key1_mapped: "value1")
29
+ end
30
+
31
+
32
+
33
+ it "should change the Hash's keys with the given block" do
34
+ hash = { key1: "value1" }
35
+ hash.map_keys! { |key| "#{key}_mapped".to_sym }
36
+ expect(hash).to eq(key1_mapped: "value1")
37
+ end
38
+
39
+ end
40
+
41
+
42
+
43
+ describe "#map_values" do
44
+
45
+ it "should return with a new Hash whose values are mapped with the given block" do
46
+ result = { key1: "value1" }.map_values { |value| "#{value}_mapped" }
47
+ expect(result).to eq(key1: "value1_mapped")
48
+ end
49
+
50
+
51
+
52
+ it "should not change the original hash" do
53
+ hash = { key1: "value1" }
54
+ hash.map_values { |value| "#{value}_mapped" }
55
+ expect(hash).to eq(key1: "value1")
56
+ end
57
+
58
+ end
59
+
60
+
61
+
62
+ describe "#map_values!" do
63
+
64
+ it "should return with a Hash whose values are mapped with the given block" do
65
+ result = { key1: "value1" }.map_values! { |value| "#{value}_mapped" }
66
+ expect(result).to eq(key1: "value1_mapped")
67
+ end
68
+
69
+
70
+
71
+ it "should change the Hash's values with the given block" do
72
+ hash = { key1: "value1" }
73
+ hash.map_values! { |value| "#{value}_mapped" }
74
+ expect(hash).to eq(key1: "value1_mapped")
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,26 @@
1
+ require "hash_transform/version"
2
+
3
+ class Hash
4
+
5
+ def map_keys!
6
+ keys.each { |key| self[yield(key)] = delete key }
7
+ self
8
+ end
9
+
10
+
11
+ def map_keys(&block)
12
+ dup.map_keys! &block
13
+ end
14
+
15
+
16
+ def map_values!
17
+ each { |key, value| self[key] = yield(value) }
18
+ self
19
+ end
20
+
21
+
22
+ def map_values(&block)
23
+ dup.map_values! &block
24
+ end
25
+
26
+ end
@@ -0,0 +1,3 @@
1
+ module HashTransform
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hash_transform
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ferenczy Péter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-30 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '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: Use this gem to extend the Hash class with useful key and value mapping
56
+ methods.
57
+ email:
58
+ - ggpeti@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - hash_transform.gemspec
69
+ - hash_transform_spec.rb
70
+ - lib/hash_transform.rb
71
+ - lib/hash_transform/version.rb
72
+ homepage: ''
73
+ licenses:
74
+ - WTFPL
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.6
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: This gem adds map_keys, map_keys!, map_values, map_values! methods to the
96
+ Hash class.
97
+ test_files: []