hash_map 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -0
- data/lib/hash_map/dsl.rb +9 -4
- data/lib/hash_map/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0a6a8bd9cc92001e37afa91b8f81bb7227cde14
|
4
|
+
data.tar.gz: 807954453bc2c7364a174597dda3bcc5d00a409d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ef4aaabb76f1ea29a981bdfe05ed7fc4c327b08eb578557b2b549f44c55889e711b5e0788f10d59ec628c2fd9f80c9e085a6b9cf31af09001cca72fed03c242
|
7
|
+
data.tar.gz: f322f64a2fbd439e47d8cb076a81dc06c807e47a5d598482445881bf34eeb072814b9fc6e70dd8ff4fb99d2e7e1c256477570e04397034186759d86d496f2fe6
|
data/README.md
CHANGED
@@ -99,6 +99,30 @@ ProfileMapper.map(original)
|
|
99
99
|
Enjoy!
|
100
100
|
|
101
101
|
### Examples:
|
102
|
+
**`form_child`:**
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
{
|
106
|
+
passenger_data: {
|
107
|
+
traveller_information: {
|
108
|
+
passenger: {
|
109
|
+
first_name: 'Juanito'
|
110
|
+
},
|
111
|
+
traveller: {
|
112
|
+
surname: 'Perez'
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
class DeepExtraction < HashMap::Base
|
119
|
+
from_child :passenger_data, :traveller_information do
|
120
|
+
property :firstname, from: [:passenger, :first_name]
|
121
|
+
property :lastname, from: [:traveller, :surname]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
102
126
|
**No 'from' key needed:**
|
103
127
|
```ruby
|
104
128
|
class Clever < HashMap::Base
|
data/lib/hash_map/dsl.rb
CHANGED
@@ -77,11 +77,16 @@ module HashMap
|
|
77
77
|
from_child(key, opts, &block)
|
78
78
|
end
|
79
79
|
|
80
|
-
def from_child(
|
81
|
-
|
80
|
+
def from_child(*args, &block)
|
81
|
+
options = args.last.is_a?(::Hash) ? args.pop : {}
|
82
|
+
key = args
|
83
|
+
flat = _nested(key, options, &block)
|
84
|
+
keys = Array.wrap(key)
|
82
85
|
flat.each do |attr|
|
83
|
-
|
84
|
-
|
86
|
+
keys.reverse.each do |k|
|
87
|
+
attr[:from].unshift(k)
|
88
|
+
attr[:from_child] ? attr[:from_child].unshift(k) : attr[:from_child] = [k]
|
89
|
+
end
|
85
90
|
end
|
86
91
|
@attributes += flat
|
87
92
|
end
|
data/lib/hash_map/version.rb
CHANGED
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.5.
|
4
|
+
version: 0.5.2
|
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: 2017-
|
11
|
+
date: 2017-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|