ja2r 0.4.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f7568684405d5bab705339641fe01bfbe4d47cad7582d5f8e18ac4c3550fa76
4
- data.tar.gz: 2a14276b05862e05c70acc866a9ab7a8ebe03755e6c08e311e042466218872e2
3
+ metadata.gz: 6c57261c49614b634002798afb8e910871587b82430fe03fbcb07ede01e00da5
4
+ data.tar.gz: 6962fea0c94bd87ce6a2b567ebae944ca8b28b560fb4141b9471314dc7526e8a
5
5
  SHA512:
6
- metadata.gz: 8b887325ba80130513d408d3249b0eb1e3441420d94339bece47c91432a07e41c0fda950023d0774dfa74abedd36fe811390db4a4e076ce5ff95795ffd16e9cf
7
- data.tar.gz: aeb13188ee1fc4ae6779bc0297ea91eb457745b452d650ae832afb994d65b3d71f08bfffd950dcb86d4a8f81470ef357cce424b3cbb794f29c053d4d8b1570f5
6
+ metadata.gz: b67fb5528e863a0e9aff8d60b98d8b188d4d243df133df1b726e0fc8f38b65d9c558e1d082469a65285f9fb1be8bc932346b12c669637eecc63233e5b763c373
7
+ data.tar.gz: 8ec89d361eece21bb856f0849216f9b4a8bdf74a07ee79c5891cf3d499de47708e06860f7eaf116040693edd6aa3223f2113e045da18d6e6d805f7165b17f47a
data/lib/ja2r/element.rb CHANGED
@@ -2,7 +2,7 @@ module JA2R
2
2
  class Element
3
3
  def initialize(origin_data)
4
4
  @origin_data = origin_data.with_indifferent_access
5
- @relationships = origin_data['relationships'] ? convert_relationship(origin_data['relationships']) : {}
5
+ @relationships = origin_data['relationships'] ? convert_relationships(origin_data['relationships']) : {}
6
6
  end
7
7
 
8
8
  attr_reader :origin_data, :relationships
@@ -52,14 +52,14 @@ module JA2R
52
52
  super
53
53
  end
54
54
 
55
- def convert_relationship(hash)
56
- Hash[hash.map do |key, data|
57
- if data['data'].is_a? Array
58
- [key, data['data'].map { |d| KlassRegistry.instantiate(d) }]
59
- else
60
- [key, KlassRegistry.instantiate(data['data'])]
61
- end
62
- end].with_indifferent_access
55
+ def convert_relationships(hash)
56
+ hash.each_with_object(ActiveSupport::HashWithIndifferentAccess.new) do |(key, data), memo|
57
+ memo[key] = if data&.[]('data').is_a?(Array)
58
+ data['data'].map { |d| KlassRegistry.instantiate(d) }
59
+ elsif data&.[]('data').is_a?(Hash)
60
+ KlassRegistry.instantiate(data&.[]('data'))
61
+ end
62
+ end
63
63
  end
64
64
  end
65
65
  end
@@ -3,6 +3,8 @@ module JA2R
3
3
  extend self
4
4
 
5
5
  def instantiate(hash)
6
+ return unless hash&.key? 'type'
7
+
6
8
  lookup(hash['type']).new(hash)
7
9
  end
8
10
 
data/lib/ja2r/parser.rb CHANGED
@@ -19,9 +19,9 @@ module JA2R
19
19
  attr_reader :hash, :object_space
20
20
 
21
21
  def parse_data
22
- if hash['data'].is_a?(Array)
22
+ if hash&.[]('data').is_a?(Array)
23
23
  parse_list
24
- elsif hash['data'].is_a?(Hash)
24
+ elsif hash&.[]('data').is_a?(Hash)
25
25
  parse_single
26
26
  end
27
27
  end
@@ -57,7 +57,7 @@ module JA2R
57
57
  object_space.dig(e.type, e.id) || e
58
58
  end
59
59
  else
60
- next unless (obj = object_space.dig(relationship.type, relationship.id))
60
+ next unless (obj = object_space.dig(relationship&.type, relationship&.id))
61
61
 
62
62
  element.relationships[key] = obj
63
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ja2r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mkon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-19 00:00:00.000000000 Z
11
+ date: 2019-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport