lasagna 0.0.2 → 0.1.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/lasagna.rb +31 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 308c6ee4c6563f7e5449fc34c0f62d90655b8066
4
- data.tar.gz: 9248bbf2e8154bbed25ac2a884d2382ae1168bac
3
+ metadata.gz: 7b36469f0ed53c726b0bb62ce30f92bb56da147b
4
+ data.tar.gz: 89a2cbed2489c66f7a7ba283e4135f218697f806
5
5
  SHA512:
6
- metadata.gz: cb56728d32d37501823942842bc819fad1d03bcfffad11485de12f05cd04d3240e3eb20a2fecef4fa761a9b82716cc91565a23693234f0d28ad45856192e7a2c
7
- data.tar.gz: d8dff913226208e0e01eb46da325c2789dea7958b758aa0bd5e40e23e73ef0cb8217dbc6e4f36798ecfd033a13d96bd807a95d69186dfe5f53aa367ecef87273
6
+ metadata.gz: bde55854f41105b595ab44f3f35f45afb8b8eebbb02df898f93b845110b7c858d80447c4366272cdfb7221c14eac1b445833e32ae9853241f74538799e5425d3
7
+ data.tar.gz: 7c87a472bf45cb9cc61fe62f38b434771f92f9b04f3e5ef2a09eb056d9ba1f52aa7c5260b0707400f413f7192da25f035433bc0b63835a72fa2840c09f839e21
data/lib/lasagna.rb CHANGED
@@ -1,5 +1,34 @@
1
1
  class Lasagna
2
- def self.hi
3
- puts "Hello lasagna!"
2
+ def self.parse(json)
3
+ if json.nil? || json['data'].nil?
4
+ return {}
5
+ end
6
+
7
+ inclusion = parse_inclusion json
8
+ parsed = []
9
+
10
+ json['data'].each do |item|
11
+ row = item['attributes'].transform_keys { |key| key.to_s.underscore }
12
+ item['relationships'].each do |key, r|
13
+ type = r['data']['type'].underscore
14
+ id = r['data']['id']
15
+ row[key] = inclusion[type] && inclusion[type][id]
16
+ end
17
+ parsed.push row
18
+ end
19
+ parsed
20
+ end
21
+
22
+ private
23
+
24
+ def self.parse_inclusion(json)
25
+ inclusion = {}
26
+ included = json['included'] || []
27
+ included.each do |include|
28
+ key = include['type'].underscore
29
+ inclusion[key] = {} if inclusion[key].nil?
30
+ inclusion[key][include['id']] = include['attributes'].transform_keys { |key| key.to_s.underscore }
31
+ end
32
+ inclusion
4
33
  end
5
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lasagna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Vdovareize