hash_remapper 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c683439dd0fa1c9ed4829b996ef023248412faa7c40062da5195e6c7f639b610
4
- data.tar.gz: 169160ed106c2da575ebbd2e8ee3a09432fdecfcb100af63f899ac08ccafd689
3
+ metadata.gz: 849f5ac471d049fc5ed4dccb35a3dc583cc326b94196378db5444a6ce6d7c7e5
4
+ data.tar.gz: caebef5d5546e43484ace97d07e9b8a3c719a11d033b6936d9c2e67be0534a41
5
5
  SHA512:
6
- metadata.gz: 10b4f4686588c177567f5f7a0653970b71e18f7bd2919166b9bca568c4ab80a020b69b7ecdd96cce2d3291359c02e7ba6ad43447053f577a768ea41c31360ed0
7
- data.tar.gz: 78fdc8e7fba05285373ac1dd8395b6d5aeec76b892ddffb1508cd79c1a34dda19283da5e7014065e30f96ce7eccbba6758231fb93f0868534f584509da600c8a
6
+ metadata.gz: 467c6ab818803bf1ac8f7c252ed60bf0ce9b02926cae155aa21cd1689aa5c05e6926716293ad45ba8c74190c6aa7b8221a7ad6658ac47394f41faefcd1369e62
7
+ data.tar.gz: 90897ecf9b5bdc3bb6ee6b60c09721a9f0a5236fd2e5f5bc4d03580beb83a337a8e36f94e0294ea8005fe0eee26a20dfc5521f43502d10a8f8ebeef73a8f58ee
data/README.md CHANGED
@@ -5,7 +5,8 @@
5
5
  </p>
6
6
 
7
7
  > A little lib which maps original keys to the new ones <sup>[*](#features)</sup>
8
- > [![Build Status](https://travis-ci.org/smileart/hash_remapper.svg?branch=master)](https://travis-ci.org/smileart/hash_remapper)
8
+ >
9
+ > [![Build Status](https://travis-ci.org/smileart/hash_remapper.svg?branch=master)](https://travis-ci.org/smileart/hash_remapper) ![Gem](https://img.shields.io/gem/v/hash_remapper.svg)
9
10
 
10
11
  ## Installation
11
12
 
@@ -331,6 +332,10 @@ HashRemapper.remap(
331
332
  # }
332
333
  ```
333
334
 
335
+ ## Examples
336
+
337
+ For advanced usage and examples see [specs](./spec/hash_remapper_spec.rb) and [examples](./exmaples)
338
+
334
339
  ## Development
335
340
 
336
341
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,100 @@
1
+ require 'hash_digger'
2
+ require 'hash_remapper'
3
+ require 'tapp'
4
+
5
+ data = {
6
+ :books => [
7
+ {
8
+ :title => "The Hitchhiker's Guide to the Galaxy",
9
+ :editions => [
10
+ {
11
+ :isbn => "978-1-9936-7490-4",
12
+ :language => "en",
13
+ :pages => 193,
14
+ :genres => [
15
+ "comic",
16
+ "science fiction"
17
+ ]
18
+ },
19
+ {
20
+ :isbn => "978-0-5762-2634-9",
21
+ :language => "en",
22
+ :pages => 208,
23
+ :genres => [
24
+ "comic",
25
+ "fiction",
26
+ "science fiction"
27
+ ]
28
+ },
29
+ {
30
+ :isbn => "978-5-4566-1998-3",
31
+ :language => "de",
32
+ :pages => 232,
33
+ :genres => [
34
+ "fiction",
35
+ "science fiction"
36
+ ]
37
+ }
38
+ ]
39
+ },
40
+ {
41
+ :title => "To Kill a Mockingbird",
42
+ :editions => [
43
+ {
44
+ :isbn => "978-4-0125-2865-3",
45
+ :language => "en",
46
+ :pages => 324,
47
+ :genres => [
48
+ "Southern Gothic",
49
+ "Bildungsroman"
50
+ ]
51
+ },
52
+ {
53
+ :isbn => "978-5-3638-3280-2",
54
+ :language => "en",
55
+ :pages => 324,
56
+ :genres => [
57
+ "magic realism"
58
+ ]
59
+ }
60
+ ]
61
+ }
62
+ ]
63
+ }
64
+
65
+ puts "Here we lose the relations between books and ISBNs:"
66
+ raw_result = HashRemapper.remap(
67
+ data,
68
+ titles: [:titles, { path: 'books.*.title' }],
69
+ isbns: [:isbns, { path: 'books.*.editions.*.*.isbn' }]
70
+ ).tapp
71
+
72
+ puts '='*50
73
+ puts
74
+
75
+ puts "Here we do a little trick splitting the path into two parts to presev relation in indexes"
76
+ isbn_result = HashRemapper.remap(
77
+ data,
78
+ titles: [:titles, { path: 'books.*.title' }],
79
+ isbns: [:isbns, { path: 'books.*.editions.*', lambda: ->(editions) { editions.collect { |edition| HashDigger::Digger.dig(data: edition, path: '*.isbn') } } }]
80
+ ).tapp
81
+
82
+ puts '='*50
83
+ puts
84
+
85
+ puts "Then we zip the data together in key => value format:"
86
+ Hash[isbn_result[:titles].zip(isbn_result[:isbns])].tapp
87
+
88
+ puts '='*50
89
+ puts ''
90
+
91
+ puts "Or create the new hashes assebling the data in any desirable structure:"
92
+ books_with_isbns = []
93
+ isbn_result[:titles].each_with_index do |t, i|
94
+ books_with_isbns << {
95
+ title: t,
96
+ isbns: isbn_result[:isbns][i].uniq
97
+ }
98
+ end
99
+
100
+ books_with_isbns.tapp
@@ -25,16 +25,16 @@ HashRemapper::GEMSPEC = Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ['lib']
27
27
 
28
- spec.add_dependency 'hash_digger', '~> 0.0', '>= 0.0.4'
28
+ spec.add_dependency 'hash_digger', '~> 0.1'
29
29
 
30
- spec.add_development_dependency 'bundler', '~> 2.0'
31
- spec.add_development_dependency 'byebug', '~> 11.0'
30
+ spec.add_development_dependency 'bundler', '~> 2.1'
31
+ spec.add_development_dependency 'byebug', '~> 11.1'
32
32
  spec.add_development_dependency 'inch', '>= 0.9.0.rc1'
33
- spec.add_development_dependency 'letters', '~> 0.4'
34
- spec.add_development_dependency 'rake', '~> 12.2'
35
- spec.add_development_dependency 'rspec', '~> 3.7'
36
- spec.add_development_dependency 'rubocop', '~> 0.51'
33
+ spec.add_development_dependency 'rake', '~> 13.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.9'
35
+ spec.add_development_dependency 'rubocop', '~> 0.91'
37
36
  spec.add_development_dependency 'rubygems-tasks', '~> 0.2'
38
- spec.add_development_dependency 'simplecov', '~> 0.15'
37
+ spec.add_development_dependency 'simplecov', '~> 0.19'
38
+ spec.add_development_dependency 'tapp', '~> 1.5'
39
39
  spec.add_development_dependency 'yard', '~> 0.9'
40
40
  end
@@ -3,7 +3,7 @@
3
3
  require 'set'
4
4
  require 'hash_digger'
5
5
 
6
- require 'letters' if ENV['DEBUG']
6
+ require 'tapp' if ENV['DEBUG']
7
7
  require 'byebug' if ENV['DEBUG']
8
8
 
9
9
  # Utility class to map original Hash keys to the new ones
@@ -1,4 +1,4 @@
1
1
  class HashRemapper
2
2
  # Current Library Version
3
- VERSION = '0.4.2'
3
+ VERSION = '0.4.3'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_remapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serge Bedzhyk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-09 00:00:00.000000000 Z
11
+ date: 2020-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hash_digger
@@ -16,48 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.0'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.0.4
19
+ version: '0.1'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0.0'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.0.4
26
+ version: '0.1'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: bundler
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '2.0'
33
+ version: '2.1'
40
34
  type: :development
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: '2.0'
40
+ version: '2.1'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: byebug
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '11.0'
47
+ version: '11.1'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: '11.0'
54
+ version: '11.1'
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: inch
63
57
  requirement: !ruby/object:Gem::Requirement
@@ -73,89 +67,89 @@ dependencies:
73
67
  - !ruby/object:Gem::Version
74
68
  version: 0.9.0.rc1
75
69
  - !ruby/object:Gem::Dependency
76
- name: letters
70
+ name: rake
77
71
  requirement: !ruby/object:Gem::Requirement
78
72
  requirements:
79
73
  - - "~>"
80
74
  - !ruby/object:Gem::Version
81
- version: '0.4'
75
+ version: '13.0'
82
76
  type: :development
83
77
  prerelease: false
84
78
  version_requirements: !ruby/object:Gem::Requirement
85
79
  requirements:
86
80
  - - "~>"
87
81
  - !ruby/object:Gem::Version
88
- version: '0.4'
82
+ version: '13.0'
89
83
  - !ruby/object:Gem::Dependency
90
- name: rake
84
+ name: rspec
91
85
  requirement: !ruby/object:Gem::Requirement
92
86
  requirements:
93
87
  - - "~>"
94
88
  - !ruby/object:Gem::Version
95
- version: '12.2'
89
+ version: '3.9'
96
90
  type: :development
97
91
  prerelease: false
98
92
  version_requirements: !ruby/object:Gem::Requirement
99
93
  requirements:
100
94
  - - "~>"
101
95
  - !ruby/object:Gem::Version
102
- version: '12.2'
96
+ version: '3.9'
103
97
  - !ruby/object:Gem::Dependency
104
- name: rspec
98
+ name: rubocop
105
99
  requirement: !ruby/object:Gem::Requirement
106
100
  requirements:
107
101
  - - "~>"
108
102
  - !ruby/object:Gem::Version
109
- version: '3.7'
103
+ version: '0.91'
110
104
  type: :development
111
105
  prerelease: false
112
106
  version_requirements: !ruby/object:Gem::Requirement
113
107
  requirements:
114
108
  - - "~>"
115
109
  - !ruby/object:Gem::Version
116
- version: '3.7'
110
+ version: '0.91'
117
111
  - !ruby/object:Gem::Dependency
118
- name: rubocop
112
+ name: rubygems-tasks
119
113
  requirement: !ruby/object:Gem::Requirement
120
114
  requirements:
121
115
  - - "~>"
122
116
  - !ruby/object:Gem::Version
123
- version: '0.51'
117
+ version: '0.2'
124
118
  type: :development
125
119
  prerelease: false
126
120
  version_requirements: !ruby/object:Gem::Requirement
127
121
  requirements:
128
122
  - - "~>"
129
123
  - !ruby/object:Gem::Version
130
- version: '0.51'
124
+ version: '0.2'
131
125
  - !ruby/object:Gem::Dependency
132
- name: rubygems-tasks
126
+ name: simplecov
133
127
  requirement: !ruby/object:Gem::Requirement
134
128
  requirements:
135
129
  - - "~>"
136
130
  - !ruby/object:Gem::Version
137
- version: '0.2'
131
+ version: '0.19'
138
132
  type: :development
139
133
  prerelease: false
140
134
  version_requirements: !ruby/object:Gem::Requirement
141
135
  requirements:
142
136
  - - "~>"
143
137
  - !ruby/object:Gem::Version
144
- version: '0.2'
138
+ version: '0.19'
145
139
  - !ruby/object:Gem::Dependency
146
- name: simplecov
140
+ name: tapp
147
141
  requirement: !ruby/object:Gem::Requirement
148
142
  requirements:
149
143
  - - "~>"
150
144
  - !ruby/object:Gem::Version
151
- version: '0.15'
145
+ version: '1.5'
152
146
  type: :development
153
147
  prerelease: false
154
148
  version_requirements: !ruby/object:Gem::Requirement
155
149
  requirements:
156
150
  - - "~>"
157
151
  - !ruby/object:Gem::Version
158
- version: '0.15'
152
+ version: '1.5'
159
153
  - !ruby/object:Gem::Dependency
160
154
  name: yard
161
155
  requirement: !ruby/object:Gem::Requirement
@@ -188,6 +182,7 @@ files:
188
182
  - Rakefile
189
183
  - bin/console
190
184
  - bin/setup
185
+ - exmaples/relations.rb
191
186
  - exmaples/weather.rb
192
187
  - hash_remapper.gemspec
193
188
  - img/hash_remapper.png
@@ -212,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
207
  - !ruby/object:Gem::Version
213
208
  version: '0'
214
209
  requirements: []
215
- rubygems_version: 3.0.1
210
+ rubygems_version: 3.1.2
216
211
  signing_key:
217
212
  specification_version: 4
218
213
  summary: A little lib which maps original keys to the new ones