hash_maps 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/.rspec ADDED
@@ -0,0 +1 @@
1
+
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2013-02-18
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,9 @@
1
+ .rspec
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ lib/hash_extensions.rb
7
+ spec/hash_extensions_spec.rb
8
+ spec/spec_helper.rb
9
+
data/README.txt ADDED
@@ -0,0 +1,55 @@
1
+ = hash_maps
2
+
3
+ * https://github.com/dsisnero/hash_maps.git
4
+
5
+ == this is intended to be an extension for hash. It adds the
6
+ following methods
7
+
8
+ * map_keys
9
+ require 'hash_extensions'
10
+ { :key => "value"}.map_keys{|k| k.to_s}
11
+ => {"key" => "value"}
12
+
13
+ * map_values
14
+ { :key => "value"}.map_values{|v| v*2}
15
+ => { :key => "valuevalue"}
16
+
17
+ * map_kv
18
+ { :key => "value", "k2" => 3}.map_kv{ |k,v| [k.to_s,v.to_s]}
19
+ => {"key"=>"value", "k2" => "3"}
20
+
21
+ * (sudo gem install)
22
+
23
+ == DEVELOPERS:
24
+
25
+ After checking out the source, run:
26
+
27
+ $ rake newb
28
+
29
+ This task will install any missing dependencies, run the tests/specs,
30
+ and generate the RDoc.
31
+
32
+ == LICENSE:
33
+
34
+ (The MIT License)
35
+
36
+ Copyright (c) 2013 FIX
37
+
38
+ Permission is hereby granted, free of charge, to any person obtaining
39
+ a copy of this software and associated documentation files (the
40
+ 'Software'), to deal in the Software without restriction, including
41
+ without limitation the rights to use, copy, modify, merge, publish,
42
+ distribute, sublicense, and/or sell copies of the Software, and to
43
+ permit persons to whom the Software is furnished to do so, subject to
44
+ the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be
47
+ included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
50
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
52
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
53
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
54
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
55
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugin :bundler
7
+
8
+ # Hoe.plugin :compiler
9
+ # Hoe.plugin :gem_prelude_sucks
10
+ # Hoe.plugin :inline
11
+ # Hoe.plugin :minitest
12
+ # Hoe.plugin :racc
13
+ # Hoe.plugin :rcov
14
+ # Hoe.plugin :rubyforge
15
+
16
+ Hoe.spec 'hash_maps' do
17
+ VERSION = '0.0.1'
18
+ developer('Dominic Sisneros', 'dsisnero@gmail.com')
19
+ # extra_deps << ['blah', '~> 1.0']
20
+ # extra_dev_deps << ['blah', '~>1.0']
21
+ # dependency(name,version,type) :type one of :[:runtime, :dev,
22
+ # :development, :developer]
23
+ dependency('hoe-bundler', '> 0.0.0', :dev)
24
+ dependency('rspec', '> 0.0.0', :dev)
25
+ dependency('ZenTest', '> 0.0.0', :dev)
26
+
27
+
28
+ ##
29
+ # Optional: Extra files you want to add to RDoc.
30
+ #
31
+ # .txt files are automatically included (excluding the obvious).
32
+
33
+ # extra_rdoc_files
34
+
35
+ ##
36
+ # Optional: The filename for the project history. [default: History.txt]
37
+
38
+ # history_file
39
+
40
+
41
+ # self.rubyforge_name = 'hash_extensions' # if different than 'hash_extensions'
42
+ end
@@ -0,0 +1,33 @@
1
+ module HashExtensions
2
+ VERSION = '0.0.1'
3
+
4
+
5
+ def map_kv
6
+ self.reduce({}) do |result,hash_array|
7
+ key,value = hash_array
8
+ new_key,new_value = yield key,value
9
+ result.merge( { new_key => new_value})
10
+ end
11
+ end
12
+
13
+
14
+ def map_keys()
15
+ self.reduce({}) do |result, hash_array|
16
+ key,value = hash_array
17
+ new_key =yield key
18
+ result.merge( { new_key => value})
19
+ end
20
+ end
21
+
22
+ def map_values()
23
+ self.reduce({}) do |result, hash_array|
24
+ key,value = hash_array
25
+ new_value = yield value
26
+ result.merge({ key => new_value})
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+
33
+ class Hash; include HashExtensions; end
@@ -0,0 +1,43 @@
1
+ require_relative 'spec_helper'
2
+
3
+ require "hash_extensions"
4
+
5
+ class Hash; include HashExtensions; end
6
+ describe HashExtensions do
7
+ before(:each) do
8
+ @h = {"name" => "hash_extensions",
9
+ "version" => 1,
10
+ why: 'to make it easier'
11
+ }
12
+ end
13
+
14
+
15
+
16
+ it "maps keys" do
17
+ expect(@h.map_keys{|k| k.to_s}).to eq(
18
+ {"name"=> "hash_extensions",
19
+ "version" => 1,
20
+ "why" => "to make it easier"
21
+ }
22
+ )
23
+ end
24
+
25
+ it "maps values" do
26
+ expect(@h.map_values{|v| v.to_s}).to eq(
27
+ {"name" => "hash_extensions",
28
+ "version" => "1",
29
+ :why => "to make it easier"
30
+ }
31
+ )
32
+ end
33
+
34
+ it "maps kv" do
35
+ expect(@h.map_kv{|k,v| [k.to_s,v.to_s]}).to eq(
36
+ {"name" => "hash_extensions",
37
+ "version" => "1",
38
+ "why" => "to make it easier"
39
+ }
40
+ )
41
+ end
42
+
43
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require 'rspec'
8
+
9
+ require 'hash_extensions'
10
+
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+ end
16
+
17
+
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hash_maps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dominic Sisneros
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.10'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.10'
30
+ - !ruby/object:Gem::Dependency
31
+ name: hoe-bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>'
36
+ - !ruby/object:Gem::Version
37
+ version: 0.0.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>'
44
+ - !ruby/object:Gem::Version
45
+ version: 0.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>'
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>'
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: ZenTest
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>'
68
+ - !ruby/object:Gem::Version
69
+ version: 0.0.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>'
76
+ - !ruby/object:Gem::Version
77
+ version: 0.0.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: hoe
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '3.5'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '3.5'
94
+ description: ''
95
+ email:
96
+ - dsisnero@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files:
100
+ - History.txt
101
+ - Manifest.txt
102
+ - README.txt
103
+ files:
104
+ - .rspec
105
+ - History.txt
106
+ - Manifest.txt
107
+ - README.txt
108
+ - Rakefile
109
+ - lib/hash_extensions.rb
110
+ - spec/hash_extensions_spec.rb
111
+ - spec/spec_helper.rb
112
+ - .gemtest
113
+ homepage: https://github.com/dsisnero/hash_maps.git
114
+ licenses: []
115
+ post_install_message:
116
+ rdoc_options:
117
+ - --main
118
+ - README.txt
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project: hash_maps
135
+ rubygems_version: 1.8.25
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: ''
139
+ test_files: []