dcm 0.0.10 → 0.0.12
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/cli.rb +7 -6
- data/lib/codinginfo.rb +25 -20
- data/lib/variant_filter.rb +27 -0
- data/lib/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d6c6d8b3341afdbe2ee6d4fbb596409e364844ca8e16552e6b2deb22756609a
|
4
|
+
data.tar.gz: 7881fdc1335265a96d70e88121dca3c5cfee693c328b1f8518a9952633e13bca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 246e46a81052ddb1c86a49c529979e7e9134b129b6d68d58756ce319b84453d2b9b9d155e424ff748eaea226ab40774f5f11971ee3a43df36374dd2b2bbbcf7e
|
7
|
+
data.tar.gz: aaec1159240e20cc19caf6be99b9f8d62c6c8c04d40441957c6f1d34febc4de28dc069fac4aca833aa795a409524457e533b584af044349b4d2b62e067fbf141
|
data/lib/cli.rb
CHANGED
@@ -11,6 +11,7 @@ require_relative "codinginfo"
|
|
11
11
|
require_relative "tempfile_handler"
|
12
12
|
require_relative "diff_viewer"
|
13
13
|
require_relative "label_selector"
|
14
|
+
require_relative "variant_filter"
|
14
15
|
require_relative "core_ext"
|
15
16
|
require_relative "version"
|
16
17
|
|
@@ -40,20 +41,20 @@ module Dcm
|
|
40
41
|
loop { LabelSelector.choose_from(list) }
|
41
42
|
end
|
42
43
|
|
43
|
-
desc "creta2begu
|
44
|
-
def creta2begu(
|
44
|
+
desc "creta2begu FILTER CODING FILE", "Convert a hierarchical DCM to a flat DCM"
|
45
|
+
def creta2begu(expr, codingpath, file)
|
45
46
|
list = parse_file(file)
|
46
47
|
|
47
|
-
puts Codinginfo.new(
|
48
|
+
puts Codinginfo.new(codingpath, VariantFilter.new(expr))
|
48
49
|
.flatten_list(list)
|
49
50
|
.to_dcm
|
50
51
|
end
|
51
52
|
|
52
|
-
desc "begu2creta
|
53
|
-
def begu2creta(
|
53
|
+
desc "begu2creta FILTER CODING FILE", "Convert a flat DCM to a hierarchical DCM"
|
54
|
+
def begu2creta(expr, codingpath, file)
|
54
55
|
list = parse_file(file)
|
55
56
|
|
56
|
-
puts Codinginfo.new(
|
57
|
+
puts Codinginfo.new(codingpath, VariantFilter.new(expr))
|
57
58
|
.unflatten_list(list)
|
58
59
|
.to_dcm
|
59
60
|
end
|
data/lib/codinginfo.rb
CHANGED
@@ -25,8 +25,8 @@ class Codinginfo
|
|
25
25
|
def to_s = "#{name}=#{value}"
|
26
26
|
def ==(other) = name == other.name
|
27
27
|
|
28
|
-
def
|
29
|
-
fail "Cannot
|
28
|
+
def combine(other)
|
29
|
+
fail "Cannot combine #{name} with #{other.name}" unless self == other
|
30
30
|
|
31
31
|
self.class.new \
|
32
32
|
name: name,
|
@@ -47,8 +47,9 @@ class Codinginfo
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def initialize(
|
50
|
+
def initialize(filepath, filter)
|
51
51
|
@doc = SimpleXlsxReader.open(filepath)
|
52
|
+
@filter = filter
|
52
53
|
@headers = []
|
53
54
|
@variants = []
|
54
55
|
@assignments = {}
|
@@ -56,11 +57,8 @@ class Codinginfo
|
|
56
57
|
overview_sheet
|
57
58
|
.rows
|
58
59
|
.each do |row|
|
59
|
-
|
60
|
-
next
|
61
|
-
next if row[1].nil? || row[3].nil?
|
62
|
-
next unless ids.any? { row[1].match?(/#{_1}/i) }
|
63
|
-
next unless row[3].match?(/CVAR/)
|
60
|
+
next unless headers_parsed?(row)
|
61
|
+
next unless filter.match?(@headers, row)
|
64
62
|
|
65
63
|
@variants << Variant.new(@headers, row)
|
66
64
|
end
|
@@ -89,21 +87,23 @@ class Codinginfo
|
|
89
87
|
end
|
90
88
|
|
91
89
|
def variant
|
92
|
-
fail "No variant matching #{
|
90
|
+
fail "No variant matching #{@filter} found!" if @variants.empty?
|
93
91
|
fail "More than one variant matching #{id} found!" if @variants.size > 1
|
94
92
|
|
95
93
|
@variants.first
|
96
94
|
end
|
97
95
|
|
98
96
|
def unflatten_list(list)
|
97
|
+
fail "No variants found matching #{@filter}" if @variants.empty?
|
98
|
+
|
99
99
|
Ecu::LabelList.new \
|
100
100
|
list.flat_map { |label|
|
101
101
|
if has_cvar_assignment?(label)
|
102
|
-
@variants.map { label.with(name: add_cvar_prefix(label, _1)) }
|
102
|
+
@variants.map { label.with(name: add_cvar_prefix(label.name, _1)) }
|
103
103
|
else
|
104
104
|
label
|
105
105
|
end
|
106
|
-
}
|
106
|
+
}.uniq
|
107
107
|
end
|
108
108
|
|
109
109
|
def flatten_list(list)
|
@@ -124,28 +124,33 @@ class Codinginfo
|
|
124
124
|
variant.cvars.any? { label.name.match?(_1.label_prefix) }
|
125
125
|
end
|
126
126
|
|
127
|
-
def add_cvar_prefix(
|
127
|
+
def add_cvar_prefix(name, variant)
|
128
128
|
variant
|
129
129
|
.cvars
|
130
|
-
.find { _1 == @assignments[
|
131
|
-
.then { _1.
|
132
|
-
.then { _1.label_prefix +
|
130
|
+
.find { _1 == @assignments[name] }
|
131
|
+
.then { _1.combine(@assignments[name]) }
|
132
|
+
.then { _1.label_prefix + name }
|
133
133
|
end
|
134
134
|
|
135
135
|
def remove_cvar_prefix(name)
|
136
136
|
name.sub(CVAR_PREFIX_REGEXP, "")
|
137
137
|
end
|
138
138
|
|
139
|
-
def
|
140
|
-
return
|
141
|
-
|
142
|
-
return unless row[
|
139
|
+
def headers_parsed?(row)
|
140
|
+
return true if @headers.any?
|
141
|
+
|
142
|
+
return false unless row[1]&.match?(/SWFK-ID/)
|
143
|
+
return false unless row[1]&.match?(/CVAR_BeguData/)
|
144
|
+
return false unless row[2]&.match?(/Kommentar/)
|
143
145
|
|
144
146
|
@headers = row
|
145
147
|
.map(&:chomp)
|
146
148
|
.map(&:lstrip)
|
147
149
|
.map(&:strip)
|
148
150
|
.map { _1.sub(/\n.*/, "") }
|
149
|
-
.tap { _1[0] =
|
151
|
+
.tap { _1[0] = :typestr }
|
152
|
+
.tap { _1[1] = :swfk_id }
|
153
|
+
.tap { _1[4] = :typekey }
|
154
|
+
.tap { _1[6] = :devkey }
|
150
155
|
end
|
151
156
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Dcm
|
2
|
+
class VariantFilter
|
3
|
+
ALLOWED_FILTERKEYS = %w(swfk_id typekey devkey)
|
4
|
+
|
5
|
+
attr_reader :key, :matchers
|
6
|
+
def initialize(expr)
|
7
|
+
unless expr.match?(/^[\w_]+\:/) && ALLOWED_FILTERKEYS.include?(expr.split(":").first)
|
8
|
+
fail "Unknown filter expression #{expr}. "
|
9
|
+
"Syntax: (#{ALLOWED_FILTERKEYS.join("|")}):value[,value2]."
|
10
|
+
end
|
11
|
+
|
12
|
+
key, matchers = expr.split(":")
|
13
|
+
@key = key.to_sym
|
14
|
+
@matchers = matchers.split(",").map { /#{_1}/i }
|
15
|
+
end
|
16
|
+
|
17
|
+
def match?(headers, row)
|
18
|
+
return false unless row[3]
|
19
|
+
return false unless row[3].match?(/CVAR/)
|
20
|
+
return false unless headers.include?(@key)
|
21
|
+
|
22
|
+
matchers.any? { row[headers.index(@key)].match?(_1) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s = "<Filter #{key}:#{matchers.join(",")}"
|
26
|
+
end
|
27
|
+
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dcm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Mueller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: automotive-ecu
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/list_colorizer.rb
|
85
85
|
- lib/selecta.rb
|
86
86
|
- lib/tempfile_handler.rb
|
87
|
+
- lib/variant_filter.rb
|
87
88
|
- lib/version.rb
|
88
89
|
homepage: https://sr.ht/~muellerj/dcm
|
89
90
|
licenses:
|