associate_rb 0.0.1
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/associate_rb.rb +7 -0
- data/lib/extensions/array_extension.rb +43 -0
- data/lib/extensions/object_extension.rb +11 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2226fb6bd49b3122bdf396d0cf45179dc6fc4c819c45ac67df4bc359338c70e6
|
4
|
+
data.tar.gz: ebbd89597b05a4cfdb5c642a7b23f73ed0f09431bc327400792aa29fa727234e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f86605f0c5dda42e23832d87f585b84ca1d0b0b6b7d93fa795ac0041bb94e9dc4ce0a49521830b5b0e15615daa9590638a8882ddb9235681b78c95e719a7aa0e
|
7
|
+
data.tar.gz: 3ec09d6dd17d3a343751bcb5c060ea4656144a548e83054eb30a8c4cf937408dd98785019b26e1667453f5bc68b98f5e4e73b1fd70c876a427331b39ec3f34b4
|
data/lib/associate_rb.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module AssociateRB
|
2
|
+
module ArrayExtension
|
3
|
+
# Associates each element of the Array with the given value
|
4
|
+
#
|
5
|
+
# @return [Hash] the association
|
6
|
+
#
|
7
|
+
# @yield [it] Executes the association block
|
8
|
+
def associate
|
9
|
+
raise ArgumentError, 'No block provided' unless block_given?
|
10
|
+
|
11
|
+
association = {}
|
12
|
+
self.each do |it|
|
13
|
+
associated = yield(it)
|
14
|
+
raise ArgumentError, 'Block does not return Hash' unless associated.is_a?(Hash)
|
15
|
+
|
16
|
+
association.merge!(yield(it))
|
17
|
+
end
|
18
|
+
association
|
19
|
+
end
|
20
|
+
|
21
|
+
# Associates each element of the Array by the value of the provided block
|
22
|
+
#
|
23
|
+
# @return [Hash] the association
|
24
|
+
#
|
25
|
+
# @yield [it] the value to be associated (becomes the key)
|
26
|
+
def associate_by
|
27
|
+
raise ArgumentError, 'No block provided' unless block_given?
|
28
|
+
|
29
|
+
self.associate { |it| yield(it).to it }
|
30
|
+
end
|
31
|
+
|
32
|
+
# Associates each element of the Array with the value of the provided block
|
33
|
+
#
|
34
|
+
# @return [Hash] the association
|
35
|
+
#
|
36
|
+
# @yield [it] the value to be associated (becomes the value)
|
37
|
+
def associate_with
|
38
|
+
raise ArgumentError, 'No block provided' unless block_given?
|
39
|
+
|
40
|
+
self.associate { |it| it.to yield(it) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: associate_rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lucas Queiroz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Easily convert arrays into hashes
|
28
|
+
email: lucascqueiroz97@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/associate_rb.rb
|
34
|
+
- lib/extensions/array_extension.rb
|
35
|
+
- lib/extensions/object_extension.rb
|
36
|
+
homepage: https://github.com/lucasqueiroz/associate-rb
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubygems_version: 3.0.3
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Kotlin's associate implemented in Ruby
|
59
|
+
test_files: []
|