dcm 0.0.11 → 0.0.13

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: 24fe5532820ef2590dd51fcb42433a4a3972b716ce5f77269653a58d33f93435
4
- data.tar.gz: 96b84123a8fe6b36916aa1648729373f896712a0a2e6a8b5301854896091c409
3
+ metadata.gz: 566406af32cf1b1fc52fd0efc038584ba2ebf65593a6320b9ca81f7039c005b4
4
+ data.tar.gz: df518e54f75ef0aae5aa6a13c004e43cc3f6658a69b79d929733a8d69ceee12e
5
5
  SHA512:
6
- metadata.gz: 6725d774fdaa8b235463a141a3b3d504d4fbc5b52e77f8dc1f0fd0b5d56388b4381f4dd718f43b7a0c588ae4aeb1d64e816bb4f1c849709274facff262872657
7
- data.tar.gz: ca12146d598edd1b8264eb19c766416c945e99df79d0ed1c020b68ef64fba92ce738416e9f4e0e05b1ceb6471b27e6e43a1a7244b394b7af6192358a0cbb9e7f
6
+ metadata.gz: 58dfaf09bf316528e3e89673dbac84569049226bb8db76120dcedd866862a15eb97e5ae58db48d31d15b677820376119bbff9fa8a7a0538724830dd953ce733b
7
+ data.tar.gz: 54cf037e406d496ada46510043be829615bddc44cc1b394ebf6b93d4d52e62df54c0b81c564e3db1c9ef09818136de625a24d8afcc0ddee2bae421e1550ef7f5
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
 
@@ -18,8 +19,6 @@ module Dcm
18
19
 
19
20
  class CLI < Thor
20
21
 
21
- ALLOWED_FILTERKEYS = [:swfk_id, :typekey, :devkey]
22
-
23
22
  desc "show FILE", "Show all labels in FILE"
24
23
  option :oneline, type: :boolean, aliases: ["-l"]
25
24
  def show(file=nil)
@@ -46,7 +45,7 @@ module Dcm
46
45
  def creta2begu(expr, codingpath, file)
47
46
  list = parse_file(file)
48
47
 
49
- puts Codinginfo.new(codingpath, parse_filter(expr))
48
+ puts Codinginfo.new(codingpath, VariantFilter.new(expr))
50
49
  .flatten_list(list)
51
50
  .to_dcm
52
51
  end
@@ -55,7 +54,7 @@ module Dcm
55
54
  def begu2creta(expr, codingpath, file)
56
55
  list = parse_file(file)
57
56
 
58
- puts Codinginfo.new(codingpath, parse_filter(expr))
57
+ puts Codinginfo.new(codingpath, VariantFilter.new(expr))
59
58
  .unflatten_list(list)
60
59
  .to_dcm
61
60
  end
@@ -256,18 +255,6 @@ module Dcm
256
255
  Ecu::LabelList.new([label])
257
256
  end
258
257
 
259
- def check_filter(expr)
260
- return if ALLOWED_FILTERKEYS.include?(expr.split(":").first)
261
-
262
- fail "Unknown filter expression #{expr}. Possible keys are #{ALLOWED_FILTERKEYS.join(", ")}. Use key:value1,value2 syntax."
263
- end
264
-
265
- def parse_filter(expr)
266
- expr
267
- .split(":")
268
- .then { { _1.to_sym => _2.split(",") } }
269
- end
270
-
271
258
  def display_list(list:, detail:, format: :tty)
272
259
  case format
273
260
  when :tty
data/lib/codinginfo.rb CHANGED
@@ -45,10 +45,13 @@ class Codinginfo
45
45
  .select { |key, _| key.match?(/^CVAR_/) }
46
46
  .map { Cvar.new(name: _1, value: _2.to_i) }
47
47
  end
48
+
49
+ def description = @properties[:swfk_id]
48
50
  end
49
51
 
50
52
  def initialize(filepath, filter)
51
53
  @doc = SimpleXlsxReader.open(filepath)
54
+ @filter = filter
52
55
  @headers = []
53
56
  @variants = []
54
57
  @assignments = {}
@@ -57,7 +60,7 @@ class Codinginfo
57
60
  .rows
58
61
  .each do |row|
59
62
  next unless headers_parsed?(row)
60
- next unless matches_filter?(row, *filter.to_a.first)
63
+ next unless filter.match?(@headers, row)
61
64
 
62
65
  @variants << Variant.new(@headers, row)
63
66
  end
@@ -85,22 +88,24 @@ class Codinginfo
85
88
  .tap { fail "Cannot find sheet Parameterdefinition" if _1.nil? }
86
89
  end
87
90
 
88
- def matches_filter?(row, key, values)
89
- return false unless row[3]
90
- return false unless row[3].match?(/CVAR/)
91
- return false unless @headers.include?(key)
92
-
93
- values.any? { row[@headers.index(key)].match?(/#{_1}/i) }
94
- end
95
-
96
91
  def variant
97
- fail "No variant matching #{id} found!" if @variants.empty?
92
+ fail "No variant matching #{@filter} found!" if @variants.empty?
98
93
  fail "More than one variant matching #{id} found!" if @variants.size > 1
99
94
 
100
95
  @variants.first
101
96
  end
102
97
 
98
+ def variants_description
99
+ [
100
+ "Created by dcm version #{Dcm::VERSION}",
101
+ "The following swfk_ids were matched:",
102
+ *@variants.map { " " + _1.description }
103
+ ]
104
+ end
105
+
103
106
  def unflatten_list(list)
107
+ fail "No variants found matching #{@filter}" if @variants.empty?
108
+
104
109
  Ecu::LabelList.new \
105
110
  list.flat_map { |label|
106
111
  if has_cvar_assignment?(label)
@@ -108,13 +113,15 @@ class Codinginfo
108
113
  else
109
114
  label
110
115
  end
111
- }.uniq
116
+ }.uniq,
117
+ variants_description
112
118
  end
113
119
 
114
120
  def flatten_list(list)
115
121
  list
116
122
  .select { !cvar_coded?(_1) || has_matching_cvar?(_1) }
117
123
  .map_int { _1.with(name: remove_cvar_prefix(_1.name)) }
124
+ .with(headers: variants_description)
118
125
  end
119
126
 
120
127
  def cvar_coded?(label)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Dcm
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.13"
3
3
  end
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.11
4
+ version: 0.0.13
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-09 00:00:00.000000000 Z
11
+ date: 2024-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: automotive-ecu
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.7
19
+ version: 0.1.8
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.7
26
+ version: 0.1.8
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -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: