dcm 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24fe5532820ef2590dd51fcb42433a4a3972b716ce5f77269653a58d33f93435
4
- data.tar.gz: 96b84123a8fe6b36916aa1648729373f896712a0a2e6a8b5301854896091c409
3
+ metadata.gz: 7d6c6d8b3341afdbe2ee6d4fbb596409e364844ca8e16552e6b2deb22756609a
4
+ data.tar.gz: 7881fdc1335265a96d70e88121dca3c5cfee693c328b1f8518a9952633e13bca
5
5
  SHA512:
6
- metadata.gz: 6725d774fdaa8b235463a141a3b3d504d4fbc5b52e77f8dc1f0fd0b5d56388b4381f4dd718f43b7a0c588ae4aeb1d64e816bb4f1c849709274facff262872657
7
- data.tar.gz: ca12146d598edd1b8264eb19c766416c945e99df79d0ed1c020b68ef64fba92ce738416e9f4e0e05b1ceb6471b27e6e43a1a7244b394b7af6192358a0cbb9e7f
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
 
@@ -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
@@ -49,6 +49,7 @@ class Codinginfo
49
49
 
50
50
  def initialize(filepath, filter)
51
51
  @doc = SimpleXlsxReader.open(filepath)
52
+ @filter = filter
52
53
  @headers = []
53
54
  @variants = []
54
55
  @assignments = {}
@@ -57,7 +58,7 @@ class Codinginfo
57
58
  .rows
58
59
  .each do |row|
59
60
  next unless headers_parsed?(row)
60
- next unless matches_filter?(row, *filter.to_a.first)
61
+ next unless filter.match?(@headers, row)
61
62
 
62
63
  @variants << Variant.new(@headers, row)
63
64
  end
@@ -85,22 +86,16 @@ class Codinginfo
85
86
  .tap { fail "Cannot find sheet Parameterdefinition" if _1.nil? }
86
87
  end
87
88
 
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
89
  def variant
97
- fail "No variant matching #{id} found!" if @variants.empty?
90
+ fail "No variant matching #{@filter} found!" if @variants.empty?
98
91
  fail "More than one variant matching #{id} found!" if @variants.size > 1
99
92
 
100
93
  @variants.first
101
94
  end
102
95
 
103
96
  def unflatten_list(list)
97
+ fail "No variants found matching #{@filter}" if @variants.empty?
98
+
104
99
  Ecu::LabelList.new \
105
100
  list.flat_map { |label|
106
101
  if has_cvar_assignment?(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.12"
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.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-09 00:00:00.000000000 Z
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: