dcm 0.1.33 → 0.1.34

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cli.rb +13 -3
  3. data/lib/codinginfo.rb +61 -42
  4. data/lib/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a924998e12ed2b4cf2792defdeb7fff452b2752c1788ca4b78f48cedb7729bea
4
- data.tar.gz: 47f31c96e0519b2d830b88766e3835f8934804868f47c8ef2267726bf323c8f8
3
+ metadata.gz: fa54183039b54a526760fa32fe22759f2f868930bb26fcf66f20b7d160d8a808
4
+ data.tar.gz: 397b66f1946176da83b407d05253f4d4a6bde08af07e455e0a21589bf2e42c45
5
5
  SHA512:
6
- metadata.gz: df4b83301ab46a86a4e59c21ef0c098fb218f225a151e1173fd8be3d54264ab1c7cfd0e0b67289a957ddcb96849ac5b345c9cd8a8877b6b7943040a7a3ec1924
7
- data.tar.gz: 0dd6fe7336e9c0bafbdc4031d179352913e3d4b570e7608e102dbdee3bd60701e2e08340ad462d4d0b72d823cc1cf0b170ca593c93c69b705ed8882386b25fb1
6
+ metadata.gz: e1f5128b226d63f2ce8f20160cc7e7bedeb02d36226b9f29f7877986f29e156c7ecb1114339aa4b75189689a32f2642804634db03ccaf77cf6e86371b779fa88
7
+ data.tar.gz: 6b7c96a428049abdfdd05fc8bbdd0d8d22a74b26a3b3f984b1796fafff6503972a2cd65d54a7c7d49f9197b179fc8a1971eb03db89dcf3e8ce628508728cb728
data/lib/cli.rb CHANGED
@@ -79,7 +79,7 @@ module Dcm
79
79
  filter = VariantFilter.new(expr)
80
80
  list = parse_file(file)
81
81
 
82
- puts Codinginfo.new(codingpath, filter)
82
+ puts Codinginfo.new(codingpath, filter, nocache: options[:nocache])
83
83
  .flatten_list(list)
84
84
  .to_dcm
85
85
  end
@@ -89,17 +89,27 @@ module Dcm
89
89
  filter = VariantFilter.new(expr)
90
90
  list = parse_file(file)
91
91
 
92
- puts Codinginfo.new(codingpath, filter)
92
+ puts Codinginfo.new(codingpath, filter, nocache: options[:nocache])
93
93
  .filter_list(list)
94
94
  .to_dcm
95
95
  end
96
96
 
97
+ desc "cretaattrs FILTER CODING", "Output attributes for a given variant"
98
+ def cretaattrs(expr, codingpath)
99
+ filter = VariantFilter.new(expr)
100
+
101
+ puts Codinginfo.new(codingpath, filter, nocache: options[:nocache])
102
+ .variant
103
+ .attributes
104
+ .to_json
105
+ end
106
+
97
107
  desc "begu2creta FILTER CODING FILE", "Convert a flat DCM to a hierarchical DCM"
98
108
  def begu2creta(expr, codingpath, file)
99
109
  filter = VariantFilter.new(expr)
100
110
  list = parse_file(file)
101
111
 
102
- puts Codinginfo.new(codingpath, filter)
112
+ puts Codinginfo.new(codingpath, filter, nocache: options[:nocache])
103
113
  .unflatten_list(list)
104
114
  .to_dcm
105
115
  end
data/lib/codinginfo.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "simple_xlsx_reader"
2
+ require_relative "file_cache"
2
3
 
3
4
  class Codinginfo
4
5
  CVAR_PREFIX_REGEXP = /^CVAR_[A-Za-z0-9_]+_\d+\./
@@ -59,6 +60,13 @@ class Codinginfo
59
60
  .map { Cvar.new(name: _1, value: _2.to_i) }
60
61
  end
61
62
 
63
+ def attributes
64
+ @attrs ||= @properties
65
+ .reject { |key, _| key.start_with?("CSIG_") }
66
+ .reject { |key, _| key.start_with?("CVAR_") }
67
+ .select { |_, val| val == 0 || val == 1 || val == "-" }
68
+ end
69
+
62
70
  def has_matching_cvar?(label)
63
71
  cvars.any? { _1.match?(label) }
64
72
  end
@@ -66,43 +74,20 @@ class Codinginfo
66
74
  def description = @properties[:swfk_id]
67
75
  end
68
76
 
69
- def initialize(filepath, filter)
70
- @doc = SimpleXlsxReader.open(filepath)
77
+ def initialize(filepath, filter, nocache: false)
71
78
  @filter = filter
72
- @headers = []
73
79
  @variants = []
74
- @assignments = {}
75
-
76
- overview_sheet
77
- .rows
78
- .each do |row|
79
- next unless headers_parsed?(row)
80
- next unless filter.match?(@headers, row)
81
80
 
82
- @variants << Variant.new(@headers, row)
83
- end
84
-
85
- param_assignment_sheet
86
- .rows
87
- .each(headers: PARAM_ASSIGNMENT_HEADERS) do |row|
88
- next if row[:cvar].nil?
81
+ parsed = nocache ? parse_xlsx(filepath) : FileCache.get(filepath) { parse_xlsx(filepath) }
89
82
 
90
- @assignments[row[:name]] = Cvar.new(name: row[:cvar], package: row[:package])
91
- end
92
- end
83
+ @headers = parsed[:headers]
84
+ @assignments = parsed[:assignments]
93
85
 
94
- def overview_sheet
95
- @doc
96
- .sheets
97
- .find { _1.name == "Gesamtübersicht" }
98
- .tap { fail "Cannot find sheet Gesamtübersicht" if _1.nil? }
99
- end
86
+ parsed[:rows].each do |row|
87
+ next unless filter.match?(@headers, row)
100
88
 
101
- def param_assignment_sheet
102
- @doc
103
- .sheets
104
- .find { _1.name == "Parameterdefinition" }
105
- .tap { fail "Cannot find sheet Parameterdefinition" if _1.nil? }
89
+ @variants << Variant.new(@headers, row)
90
+ end
106
91
  end
107
92
 
108
93
  def variant
@@ -167,21 +152,55 @@ class Codinginfo
167
152
  name.sub(CVAR_PREFIX_REGEXP, "")
168
153
  end
169
154
 
170
- def headers_parsed?(row)
171
- return true if @headers.any?
155
+ private
156
+
157
+ def parse_xlsx(filepath)
158
+ doc = SimpleXlsxReader.open(filepath)
159
+ headers = []
160
+ rows = []
161
+ assignments = {}
162
+
163
+ doc.sheets
164
+ .find { _1.name == "Gesamtübersicht" }
165
+ .tap { fail "Cannot find sheet Gesamtübersicht" if _1.nil? }
166
+ .rows
167
+ .each do |row|
168
+ unless headers.any?
169
+ next unless parse_headers!(headers, row)
170
+ next
171
+ end
172
+ rows << row
173
+ end
174
+
175
+ doc.sheets
176
+ .find { _1.name == "Parameterdefinition" }
177
+ .tap { fail "Cannot find sheet Parameterdefinition" if _1.nil? }
178
+ .rows
179
+ .each(headers: PARAM_ASSIGNMENT_HEADERS) do |row|
180
+ next if row[:cvar].nil?
181
+
182
+ assignments[row[:name]] = Cvar.new(name: row[:cvar], package: row[:package])
183
+ end
184
+
185
+ { headers: headers, rows: rows, assignments: assignments }
186
+ end
172
187
 
188
+ def parse_headers!(headers, row)
173
189
  return false unless row[1]&.match?(/SWFK-ID/)
174
190
  return false unless row[1]&.match?(/CVAR_BeguData/)
175
191
  return false unless row[2]&.match?(/Kommentar/)
176
192
 
177
- @headers = row
178
- .map(&:chomp)
179
- .map(&:lstrip)
180
- .map(&:strip)
181
- .map { _1.sub(/\n.*/, "") }
182
- .tap { _1[0] = :typestr }
183
- .tap { _1[1] = :swfk_id }
184
- .tap { _1[4] = :typekey }
185
- .tap { _1[6] = :devkey }
193
+ headers.replace(
194
+ row
195
+ .map(&:chomp)
196
+ .map(&:lstrip)
197
+ .map(&:strip)
198
+ .map { _1.sub(/\n.*/, "") }
199
+ .tap { _1[0] = :typestr }
200
+ .tap { _1[1] = :swfk_id }
201
+ .tap { _1[4] = :typekey }
202
+ .tap { _1[6] = :devkey }
203
+ )
204
+ true
186
205
  end
187
206
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dcm
2
- VERSION = "0.1.33"
2
+ VERSION = "0.1.34"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dcm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.33
4
+ version: 0.1.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Mueller