datanorm 1.0.1 → 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 322ca5c2dbafa91a1c434f0bef802c668663d15df12e268cebd55d0f5d589e9f
|
4
|
+
data.tar.gz: b6552e47e101c2f41c4ed48fc64942dfbc735b26ce6d60bc8b83aacd680e487c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
111
|
+
extra_reference.read&.fetch(:matchcode)
|
112
112
|
end
|
113
113
|
|
114
114
|
def alternative_id
|
115
|
-
extra_reference.read
|
115
|
+
extra_reference.read&.fetch(:alternative_id)
|
116
116
|
end
|
117
117
|
|
118
118
|
def ean
|
119
|
-
extra_reference.read
|
119
|
+
extra_reference.read&.fetch(:ean)
|
120
120
|
end
|
121
121
|
|
122
122
|
def category_id
|
123
|
-
extra_reference.read
|
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
|
-
|
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
|
-
|
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
|
data/lib/datanorm/file.rb
CHANGED
@@ -33,6 +33,7 @@ module Datanorm
|
|
33
33
|
::CSV.foreach(path, **options) do |columns|
|
34
34
|
line_number += 1
|
35
35
|
next if line_number == 1 # Skip header, it's parsed separately
|
36
|
+
next if columns.empty? # Empty line
|
36
37
|
|
37
38
|
yield ::Datanorm::Lines::Parse.call(version:, columns:, source_line_number: line_number)
|
38
39
|
end
|