datanorm 1.0.2 → 1.0.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
  SHA256:
3
- metadata.gz: 157ab57a1e003bd67078ed80ff60a3321e424b3f13b9cbd9d568fa8b66e4f4ef
4
- data.tar.gz: 42a35c9c02d4c22391cff9a067565bf2b2320e05c57bb5dfe3bd1845cad7b59a
3
+ metadata.gz: 322ca5c2dbafa91a1c434f0bef802c668663d15df12e268cebd55d0f5d589e9f
4
+ data.tar.gz: b6552e47e101c2f41c4ed48fc64942dfbc735b26ce6d60bc8b83aacd680e487c
5
5
  SHA512:
6
- metadata.gz: f7a112872947727f6ee390a5ed43fa0c4071fa52712d22cd7355d2d3f63e93579c45f59fb155cdaea4f2fab34eb2b76e51865fb3b3ef43e18697e987341c76ba
7
- data.tar.gz: a3ba8c8ef11ef6d1ea6c21b822e255392eb608e63e703b2134e631e72dd689060eb3e46355a48ef4a9d0574ac595bdaad37c300f256080cd37eaad7bcef47088
6
+ metadata.gz: 558a691b8d6d37121a5a9c4d71c0f519991cea4dff3a9a7a9c10ef344782d1072d25348e488955205e170c7fa3fc9e37fbd43c8f4f334008342a69cbeb8867ad
7
+ data.tar.gz: 8ffa635f8f6c97b340335622cbd6ea5ecfadf998bde2126a6317c18da694f71a24c06088242ed532b5638d6e3ba84e1592b2cb916583ebeec1924059b08617dd
@@ -53,7 +53,7 @@ module Datanorm
53
53
  # Instead, we choose one or the other.
54
54
  return dimension_content if dimension_content && !dimension_content.strip.empty?
55
55
 
56
- text_reference.read
56
+ text_reference&.read
57
57
  end
58
58
 
59
59
  # -----------------------
@@ -108,19 +108,19 @@ module Datanorm
108
108
  # -----------------
109
109
 
110
110
  def matchcode
111
- extra_reference.read[:matchcode]
111
+ extra_reference.read&.fetch(:matchcode)
112
112
  end
113
113
 
114
114
  def alternative_id
115
- extra_reference.read[:alternative_id]
115
+ extra_reference.read&.fetch(:alternative_id)
116
116
  end
117
117
 
118
118
  def ean
119
- extra_reference.read[:ean]
119
+ extra_reference.read&.fetch(:ean)
120
120
  end
121
121
 
122
122
  def category_id
123
- extra_reference.read[:category_id]
123
+ extra_reference.read&.fetch(:category_id)
124
124
  end
125
125
 
126
126
  # -------
@@ -133,7 +133,7 @@ module Datanorm
133
133
 
134
134
  def as_json
135
135
  # Adding referenced attributes that were cached to disk during preprocessing.
136
- json.merge(description:, prices: prices.map(&:as_json)).merge(extra_reference.read)
136
+ json.merge(description:, prices: prices.map(&:as_json)).merge(extra_reference.read || {})
137
137
  end
138
138
 
139
139
  def to_json(...)
@@ -20,17 +20,26 @@ module Datanorm
20
20
  private
21
21
 
22
22
  def read!
23
- if parse_json
24
- JSON.parse(path.read, symbolize_names: true) if path.file?
23
+ return unless path.file?
25
24
 
25
+ if parse_json
26
+ read_json!
26
27
  elsif path.file?
27
- if split_newlines
28
- path.read.split("\n")
29
- else
30
- path.read
31
- end
28
+ read_file!
32
29
  end
33
30
  end
31
+
32
+ def read_file!
33
+ if split_newlines
34
+ path.read.split("\n")
35
+ else
36
+ path.read
37
+ end
38
+ end
39
+
40
+ def read_json!
41
+ JSON.parse(path.read, symbolize_names: true)
42
+ end
34
43
  end
35
44
  end
36
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datanorm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - halo