datanorm 1.0.2 → 1.0.4
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 +4 -4
- data/lib/datanorm/documents/assembles/product.rb +6 -6
- data/lib/datanorm/documents/assembles/reference.rb +16 -7
- data/lib/datanorm/header.rb +24 -0
- data/lib/datanorm/headers/v4/title.rb +38 -0
- data/lib/datanorm/headers/v5/title.rb +33 -0
- data/lib/datanorm.rb +2 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba35b7a1d5969153035572f2d779c17b7686281448a4b2dbaa9d24082ca1fc6e
|
4
|
+
data.tar.gz: 83250ea0b2691f52ff92ca277e735579f52e0bfe46ee412d1f1fa65e90c2c39b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 263169ffa30220c0c48320d993aeb7977bbe9f037c757a52f201f6444f10ec9893c4450ef54c24979cfbb6af7c1120d808d98ef3d09d76736f1102dcee2e4053
|
7
|
+
data.tar.gz: 72095bf55d2bb18017c1a45c8f6393b4ab8a3579eebd03a5ee3684e72f54a06fb5c397f885ced36cc29683afc6e4cef63c5a55b3fa8d6997fa456caa3395a63c
|
@@ -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/header.rb
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
module Datanorm
|
4
4
|
# Represents the first line of a DATANORM file.
|
5
|
+
#
|
6
|
+
# Zeichen 1: Satzkennzeichen für Vorlaufsatz: immer „V“
|
7
|
+
# Zeichen 2: freie Verwendung
|
8
|
+
# Zeichen 3-8: Datum im Format TTMMJJ, darf für Cadia nicht leer sein
|
9
|
+
# Zeichen 9-48: Infotext1 (Bezeichnung des Datenlieferanten), darf für Cadia nicht leer sein
|
10
|
+
# Zeichen 49-88: Infotext2
|
11
|
+
# Zeichen 89-123: Infotext3
|
12
|
+
# Zeichen 124-125: Datanormversion (für Cadia zwingend 04)
|
13
|
+
# Zeichen 126-128: Währung (im Regelfall EUR)
|
14
|
+
#
|
5
15
|
class Header
|
6
16
|
def initialize(line:)
|
7
17
|
@line = line.to_s
|
@@ -23,6 +33,12 @@ module Datanorm
|
|
23
33
|
@date = parse_date
|
24
34
|
end
|
25
35
|
|
36
|
+
def title
|
37
|
+
return @title if defined?(@title)
|
38
|
+
|
39
|
+
@title = parse_title
|
40
|
+
end
|
41
|
+
|
26
42
|
private
|
27
43
|
|
28
44
|
attr_reader :line
|
@@ -42,5 +58,13 @@ module Datanorm
|
|
42
58
|
::Datanorm::Headers::V4::Date.call(line:)
|
43
59
|
end
|
44
60
|
end
|
61
|
+
|
62
|
+
def parse_title
|
63
|
+
if version.five?
|
64
|
+
::Datanorm::Headers::V5::Title.call(line:)
|
65
|
+
elsif version.four?
|
66
|
+
::Datanorm::Headers::V4::Title.call(line:)
|
67
|
+
end
|
68
|
+
end
|
45
69
|
end
|
46
70
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datanorm
|
4
|
+
module Headers
|
5
|
+
module V4
|
6
|
+
# Parses a Vendor from the raw first line of a Datanorm file.
|
7
|
+
class Title
|
8
|
+
include Calls
|
9
|
+
|
10
|
+
option :line
|
11
|
+
|
12
|
+
def call
|
13
|
+
::Datanorm::Helpers::Utf8.call all_texts
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
# Every supplier uses these three text fields differently.
|
19
|
+
# Best to return the entire thing.
|
20
|
+
def all_texts
|
21
|
+
"#{infotext1} #{infotext2} #{infotext3}".gsub(/\s+/, ' ').strip
|
22
|
+
end
|
23
|
+
|
24
|
+
def infotext1
|
25
|
+
line[8..47]
|
26
|
+
end
|
27
|
+
|
28
|
+
def infotext2
|
29
|
+
line[48..87]
|
30
|
+
end
|
31
|
+
|
32
|
+
def infotext3
|
33
|
+
line[88..122]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datanorm
|
4
|
+
module Headers
|
5
|
+
module V5
|
6
|
+
# rubocop:disable Layout/LineLength
|
7
|
+
#
|
8
|
+
# Parses a Vendor from the raw first line of a Datanorm file.
|
9
|
+
#
|
10
|
+
# Examples:
|
11
|
+
# V;050;A;20200406;EUR;Example GmbH;Produktdaten;;;;;;;;;
|
12
|
+
# V;050;A;20201210;EUR;Produktkatalog 2021;ACME inc.;;;;;;;;;
|
13
|
+
# V;050;A;20200730;EUR;Artikelstammdaten Deutschland, 29_DE;;EXAMPLE;EXAMPLE ELECTRONIC GMBH;www.example.de;info@example.de;Examplestr. 60;D;73434;Examplecity;
|
14
|
+
#
|
15
|
+
# rubocop:enable Layout/LineLength
|
16
|
+
class Title
|
17
|
+
include Calls
|
18
|
+
|
19
|
+
option :line
|
20
|
+
|
21
|
+
def call
|
22
|
+
::Datanorm::Helpers::Utf8.call columns[5..14].join(' ').gsub(/\s+/, ' ').strip
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def columns
|
28
|
+
line.split(';')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/datanorm.rb
CHANGED
@@ -16,8 +16,10 @@ require 'datanorm/helpers/utf8'
|
|
16
16
|
require 'datanorm/helpers/filename'
|
17
17
|
|
18
18
|
require 'datanorm/headers/v4/date'
|
19
|
+
require 'datanorm/headers/v4/title'
|
19
20
|
require 'datanorm/headers/v4/version'
|
20
21
|
require 'datanorm/headers/v5/date'
|
22
|
+
require 'datanorm/headers/v5/title'
|
21
23
|
require 'datanorm/headers/v5/version'
|
22
24
|
|
23
25
|
require 'datanorm/lines/parse'
|
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.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- halo
|
@@ -110,8 +110,10 @@ files:
|
|
110
110
|
- lib/datanorm/file.rb
|
111
111
|
- lib/datanorm/header.rb
|
112
112
|
- lib/datanorm/headers/v4/date.rb
|
113
|
+
- lib/datanorm/headers/v4/title.rb
|
113
114
|
- lib/datanorm/headers/v4/version.rb
|
114
115
|
- lib/datanorm/headers/v5/date.rb
|
116
|
+
- lib/datanorm/headers/v5/title.rb
|
115
117
|
- lib/datanorm/headers/v5/version.rb
|
116
118
|
- lib/datanorm/helpers/filename.rb
|
117
119
|
- lib/datanorm/helpers/utf8.rb
|
@@ -137,6 +139,7 @@ licenses:
|
|
137
139
|
- MIT
|
138
140
|
metadata:
|
139
141
|
bug_tracker_uri: https://github.com/halo/datanorm/issues
|
142
|
+
changelog_uri: https://github.com/halo/datanorm/blob/master/CHANGELOG.md
|
140
143
|
rubygems_mfa_required: 'true'
|
141
144
|
source_code_uri: https://github.com/halo/datanorm
|
142
145
|
rdoc_options: []
|