datanorm 0.0.1 → 1.0.0
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/README.md +24 -2
- data/lib/datanorm/document.rb +3 -3
- data/lib/datanorm/documents/assemble.rb +7 -1
- data/lib/datanorm/documents/preprocess.rb +4 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f81183cf69ef2798729afff7dcb246230e46daf3d049c14b9f2d5d2e373f68a5
|
4
|
+
data.tar.gz: fb025bfbd9b8a5405098bf187e9f438bda2e6b82ac28e554d046e9ccfff4895e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbc711307ec3c2783a98c31b8ba3ef364bf206d82910d7f5423bf93a4a953efbb1552139963824def5e3271a5518c3085c65a3c6814385f03c2df7b35ee9bf1d
|
7
|
+
data.tar.gz: d8235f4fd9be07113abc53ba29c9bd4cff955d1201f4549dc2793d8e732f08c20be94f238a00357fe4fab394d37583e686085a08a8ea1e5bcc260cf3bea4d935
|
data/README.md
CHANGED
@@ -94,7 +94,27 @@ I went for a parsing mechanism that works every time, with every file, at the ex
|
|
94
94
|
|
95
95
|
If you have a `DATANORM.001` and also a `DATPREIS.001`, you must concatenate those two files into one file first (their versions need to be the same). The resulting, merged file is what you provide to this Rubygem.
|
96
96
|
|
97
|
-
|
97
|
+
### Quick Usage
|
98
|
+
|
99
|
+
If you want one product at a time (without having to deal with the complexities of Datanorm), you can use this:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
document = Datanorm::Document.new(path: 'datanorm.001')
|
103
|
+
|
104
|
+
puts document.header
|
105
|
+
puts document.version
|
106
|
+
|
107
|
+
document.each do |product|
|
108
|
+
puts product.title
|
109
|
+
puts product.to_json
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
113
|
+
Notice that it can take a long time until the first product is yielded due to the preprocessing that takes place at first.
|
114
|
+
|
115
|
+
### Usage with Progress
|
116
|
+
|
117
|
+
If you want to see the progress, you can use the following:
|
98
118
|
|
99
119
|
```ruby
|
100
120
|
document = Datanorm::Document.new(path: 'datanorm.001')
|
@@ -102,7 +122,7 @@ document = Datanorm::Document.new(path: 'datanorm.001')
|
|
102
122
|
puts document.header
|
103
123
|
puts document.version
|
104
124
|
|
105
|
-
document.each do |product, progress|
|
125
|
+
document.each(yield_progress: true) do |product, progress|
|
106
126
|
# Once pre-processing is complete, you'll start to get products here
|
107
127
|
puts product # <- can be nil in the beginning
|
108
128
|
|
@@ -111,6 +131,8 @@ document.each do |product, progress|
|
|
111
131
|
end
|
112
132
|
```
|
113
133
|
|
134
|
+
### Bare Datanorm parsing
|
135
|
+
|
114
136
|
In case you only want the raw Datanorm file one line at a time as Ruby Objects, you can use this:
|
115
137
|
|
116
138
|
```ruby
|
data/lib/datanorm/document.rb
CHANGED
@@ -28,13 +28,13 @@ module Datanorm
|
|
28
28
|
file.version
|
29
29
|
end
|
30
30
|
|
31
|
-
def each(&)
|
31
|
+
def each(yield_progress: false, &)
|
32
32
|
unless @preprocessed
|
33
|
-
::Datanorm::Documents::Preprocess.call(file:, workdir:, &)
|
33
|
+
::Datanorm::Documents::Preprocess.call(file:, workdir:, yield_progress:, &)
|
34
34
|
@preprocessed = true
|
35
35
|
end
|
36
36
|
|
37
|
-
::Datanorm::Documents::Assemble.call(workdir:, &)
|
37
|
+
::Datanorm::Documents::Assemble.call(workdir:, yield_progress:, &)
|
38
38
|
ensure
|
39
39
|
# At this point all yields have gone through and we can clean up.
|
40
40
|
workdir.rmtree unless ENV['DEBUG_DATANORM']
|
@@ -8,13 +8,19 @@ module Datanorm
|
|
8
8
|
include ::Datanorm::Logging
|
9
9
|
|
10
10
|
option :workdir
|
11
|
+
option :yield_progress, default: -> { false }
|
11
12
|
|
12
13
|
def call
|
13
14
|
return unless products_file.file?
|
14
15
|
|
15
16
|
::File.foreach(products_file) do |json|
|
16
17
|
progress.increment!
|
17
|
-
|
18
|
+
|
19
|
+
if yield_progress
|
20
|
+
yield ::Datanorm::Documents::Assembles::Product.new(json:, workdir:), progress
|
21
|
+
else
|
22
|
+
yield ::Datanorm::Documents::Assembles::Product.new(json:, workdir:)
|
23
|
+
end
|
18
24
|
end
|
19
25
|
end
|
20
26
|
|
@@ -10,6 +10,7 @@ module Datanorm
|
|
10
10
|
|
11
11
|
option :file
|
12
12
|
option :workdir
|
13
|
+
option :yield_progress, default: -> { false }
|
13
14
|
|
14
15
|
def call
|
15
16
|
FileUtils.mkdir_p(workdir)
|
@@ -18,7 +19,9 @@ module Datanorm
|
|
18
19
|
::Datanorm::Documents::Preprocesses::Process.call(workdir:, record:)
|
19
20
|
|
20
21
|
progress.increment!
|
21
|
-
|
22
|
+
if yield_progress
|
23
|
+
yield nil, progress # No items to yield during preprocess.
|
24
|
+
end
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|