hash_map 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 009df32bde8c5f75cdf065ff8feb8c56a34e613e
4
- data.tar.gz: 83ec663c7783abec75fd9bb19369075b2c46976c
3
+ metadata.gz: c4012172f5ca69e9686260220452ccdc5f7fd4d2
4
+ data.tar.gz: 0a8a23e6add10541e7fb5b0cf81f20c595897d33
5
5
  SHA512:
6
- metadata.gz: 4d7dfcef7e69885a271fef3bcf86fa62a5aaab21640de5c23828ffd65e6b49871a0ee8dff2bb96b6a35711221281bda91c4a1d77a408272fc976357e759b0c8a
7
- data.tar.gz: dea4676ba01aa6e0300b491d3a747746549cc3eb48f5ac78166a3d2f6ffa64b5af11a55ba9b0c9fb3ddb2b8440bfebf168931749bbb20b197c6e2061abe85255
6
+ metadata.gz: f2537edf596a989fd26c3f9bbd99f45fbc2a952187fd6bf80aebc47fdb97f4af2ed086012ec9bd4f7faa134b46b3f25ec5a217a93c9e52a1ae974def8cdb2d50
7
+ data.tar.gz: f3982bbf5f523cc049d0e7213f3bda29da840f18176acc56ad6bf1f4253853c1cb35ec3af79764808d6bd62ac165893f1d47c8669c88d6ca6dc9c45c982db0ea
data/README.md CHANGED
@@ -124,6 +124,22 @@ class Collections < HashMap::Base
124
124
  end
125
125
  ```
126
126
 
127
+ The collection method always treats the value as an `Array` and it always returns an `Array`. If the value is not an `Array` it will be wrapped in a new one. If the value is `nil` it always returns `[]`.
128
+
129
+ ```ruby
130
+ Collections.map({ things: nil})
131
+ => {
132
+ things: []
133
+ numbers: []
134
+ }
135
+
136
+ Collections.map({ numbers: '1'})
137
+ => {
138
+ things: []
139
+ numbers: [1]
140
+ }
141
+ ```
142
+
127
143
  **Methods:**
128
144
 
129
145
  You can create your helpers in the mapper and call them inside the block
@@ -1,6 +1,5 @@
1
1
  module HashMap
2
2
  class Mapper
3
- class CanNotMapCollection < StandardError; end
4
3
  attr_reader :original, :hash_map
5
4
  def initialize(original, hash_map)
6
5
  @original = HashWithIndifferentAccess.new(original)
@@ -31,16 +30,10 @@ module HashMap
31
30
 
32
31
  def map_collection(struct)
33
32
  value = get_value_from_key(struct)
34
- errors_for_collection(value, struct)
33
+ value = Array.wrap(value)
35
34
  value.map { |elem| struct[:mapper].call(elem) }
36
35
  end
37
36
 
38
- def errors_for_collection(value, struct)
39
- unless value.respond_to?(:map)
40
- fail CanNotMapCollection, "'#{value.class}' does not respond to '#map'"
41
- end
42
- end
43
-
44
37
  def get_value_from_key(struct, from = :from)
45
38
  struct[from].inject(original) do |output, k|
46
39
  break unless output.respond_to?(:[])
@@ -1,3 +1,3 @@
1
1
  module HashMap
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_map
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artur Pañach
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-23 00:00:00.000000000 Z
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler