map_h 0.1.0

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: efc789fcd71de8615a2b205b6dda21738e64d065
4
+ data.tar.gz: 1409908838ff2e284f6004399c72a6fabd678f9b
5
+ SHA512:
6
+ metadata.gz: e18dbd06d15b9388cc3897e0c10327809f536bd2aeac0f15e2cfc30609f9081ae17a14cb7d90f539df76560dbcde8cef79c7877ff6f552470a25e15d893c1c2c
7
+ data.tar.gz: 7462c7243ab2094deb291efebd8b922616c3992cc614ebbc1759396a7dce260dba7ad9a4babb98f5e1d66eb8e033744e75ea1c6100651bb9075f8cab6794ee95
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ - 2.2.4
5
+ - 2.1.8
6
+ - 2.0.0
7
+ - 1.9.3
8
+ - rbx
9
+ - jruby-19mode
10
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in map_h.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Rich Daley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,73 @@
1
+ # map_h
2
+
3
+ Adds a `map_h` method to Enumerable for easily building hashes from a
4
+ given block.
5
+
6
+ [![Gem Version](https://img.shields.io/gem/v/map_h.svg?style=flat)](https://rubygems.org/gems/map_h)
7
+ [![Build Status](https://img.shields.io/travis/fishpercolator/map_h/master.svg?style=flat)](https://travis-ci.org/fishpercolator/map_h)
8
+
9
+ This is similar to the existing `map` method, but retains the original values
10
+ as the keys in the resulting hash.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application’s Gemfile:
15
+
16
+ ```ruby
17
+ gem 'map_h'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ ```sh
23
+ $ bundle
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ The method will be added to all Enumerable objects when you:
29
+
30
+ ```ruby
31
+ require 'map_h'
32
+ ```
33
+
34
+ To use `map_h`, pass it a block. For example:
35
+
36
+ ```ruby
37
+ ['john', 'paul', 'george', 'ringo'].map_h { |name| name.length }
38
+ # => {'john' => 4, 'paul' => 4, 'george' => 6, 'ringo' => 5}
39
+ ```
40
+
41
+ Or you can use the shorthand `Symbol#to_proc` syntax:
42
+
43
+ ```ruby
44
+ ['john', 'paul', 'george', 'ringo'].map_h(&:length)
45
+ # => {'john' => 4, 'paul' => 4, 'george' => 6, 'ringo' => 5}
46
+ ```
47
+
48
+ If the Enumerable yields multiple values (e.g. Hash), an array of these
49
+ values will be used as the key:
50
+
51
+ ```ruby
52
+ {
53
+ 'george' => 'guitar',
54
+ 'ringo' => 'drums'
55
+ }.map_h {|name, instrument| "#{instrument}: #{name}"}
56
+ # => {
57
+ # ['george', 'guitar'] => "guitar: george",
58
+ # ['ringo', 'drums'] => "drums: ringo"
59
+ # }
60
+ ```
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/map_h. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
69
+
70
+ ## Future
71
+
72
+ * Have `map_h` return an Enumerator instead of raising an exception if no
73
+ block is passed.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ module Enumerable
2
+ # Similar to Enumerable#map, but builds a hash of the results using
3
+ # the original value as the key.
4
+ #
5
+ # ['john', 'paul', 'george', 'ringo'].map_h { |name| name.length }
6
+ # # => {'john' => 4, 'paul' => 4, 'george' => 6, 'ringo' => 5}
7
+ def map_h
8
+ {}.tap do |result|
9
+ each do |key|
10
+ result[key] = yield key
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "map_h"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["Rich Daley"]
9
+ spec.email = ["rich@fishpercolator.co.uk"]
10
+
11
+ spec.summary = %q{Adds a map_h method to Enumerable for easily building hashes}
12
+ spec.description = %q{Enumerable#map_h creates a hash using each element of the Enumerable.}
13
+ spec.homepage = "https://github.com/fishpercolator/map_h"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.10"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "rspec"
22
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: map_h
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rich Daley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-07 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: Enumerable#map_h creates a hash using each element of the Enumerable.
56
+ email:
57
+ - rich@fishpercolator.co.uk
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - lib/map_h.rb
71
+ - map_h.gemspec
72
+ homepage: https://github.com/fishpercolator/map_h
73
+ licenses:
74
+ - MIT
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.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Adds a map_h method to Enumerable for easily building hashes
96
+ test_files: []