mapify 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/mapify.rb +31 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0260042d42bbca007c33c324704364ace62f0bdd
|
4
|
+
data.tar.gz: c25bf6bfb7118e3923534a827c9ea7a4ebb46333
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2035df10ce37ce3df786ce07434775588d93cfc53e84fe9ac8112b932de100d0ae5a451641bb3ae4adf8f3be1c821f69aeda912a8c5d946aba4a3cba3374d1f7
|
7
|
+
data.tar.gz: ae55ca64c9db750a0b18913687eb834cc5407e8530b6bfdd3344657e21606e81fd98d010f40b36c308590891ea819e75d071624c55ce264dc5e6c997d8a800c2
|
data/lib/mapify.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Enumerable
|
2
|
+
def mapify(*args)
|
3
|
+
fail_fast?(args)
|
4
|
+
|
5
|
+
map do |object|
|
6
|
+
args.map do |arg|
|
7
|
+
object.public_send(arg)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def hashify(*args)
|
13
|
+
fail_fast?(args)
|
14
|
+
|
15
|
+
map do |object|
|
16
|
+
args.reduce({}) do |hash, arg|
|
17
|
+
hash[arg] = object.public_send(arg)
|
18
|
+
hash
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def all_symbol_args?(args)
|
25
|
+
args.find{|x| x.class != Symbol}.nil?
|
26
|
+
end
|
27
|
+
|
28
|
+
def fail_fast?(args)
|
29
|
+
raise ArgumentError, 'All arguments must be symbols' unless all_symbol_args?(args) && !args.empty?
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mapify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Butcher
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Map arrays (or hashes, with Enumerable.hashify) of attributes out of
|
14
|
+
enumerables of objects, passing symbols as arguments.
|
15
|
+
email: cbutcher@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/mapify.rb
|
21
|
+
homepage: http://rubygems.org/gems/mapify
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.2.2
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Mapify
|
45
|
+
test_files: []
|