automotive-ecu 0.1.3 → 0.1.5

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: 3adf406568cc23075ab176db5d171365057400613aa2ea668e217247d2734dd0
4
- data.tar.gz: d0367f0a39c76cc2094600440a22f39a8da32118acae23419e3d95abb68910e8
3
+ metadata.gz: b9258d168cddd58d8fe69e82099c079bab80e8c7568f7e6d6e94c64f86f96388
4
+ data.tar.gz: 984ff33b0ff2973a4d0e687241447eef1b263b2c4129d2f14d5daed44be56c79
5
5
  SHA512:
6
- metadata.gz: f6027c77ae6110600b72ffab9611ba97e1ee6c95852f23cfbeb96c4afd09de25ddc84fd4ca220186f35b2922a8a7252d647a8d1c16f777c0b94b3b04e33cde05
7
- data.tar.gz: 276b5f1382cc619af06908f6dfc5f090fe26f238b55c13ee07e3330f1cc233c2701f0b15a12ef1d12f7e24b0d3ef95ef4332dff7629d959060aa0f4f814c8dae
6
+ metadata.gz: 6418a2fadf25cda97567eaa0fc38a16b81c6fd841b33c0e1f5e85681f0ca38044f8524967b044ea53d6f4e4387af082529c7dbdbbc8ea2cc90c2d4b1fffc83e7
7
+ data.tar.gz: cf113d96b84b68c92acc3ae0d6485565da0db3491648a20448a7c286925d6d891e086d96bf97badd111d3115bc873bf0d07458ed37e70d1b9372f8f8c434803b
@@ -4,8 +4,10 @@ class Ecu
4
4
  %r{FESTWERT\s+(?<name>[A-Za-z0-9\._]+)}
5
5
  end
6
6
 
7
- def to_dcm
8
- "#{type.upcase} #{name}\n".tap do |str|
7
+ def to_dcm(indented=false)
8
+ fmtstr = indented ? "%-26s%s\n" : "%s %s\n"
9
+
10
+ sprintf(fmtstr, type.upcase, name).tap do |str|
9
11
  str << " LANGNAME #{description.enquote}\n" if description
10
12
  str << " FUNKTION #{function}\n" if function
11
13
  str << " EINHEIT_W #{unit.enquote}\n" if unit
@@ -3,11 +3,13 @@ require_relative "../../../core_ext"
3
3
  class Ecu
4
4
  class Festwerteblock < Label
5
5
  def self.dcm_header
6
- %r{FESTWERTEBLOCK\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)(?:\s+@\s+(?<ydim>\d+))?}
6
+ %r{^FESTWERTEBLOCK\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)(?:\s+@\s+(?<ydim>\d+))?}
7
7
  end
8
8
 
9
- def to_dcm
10
- "FESTWERTEBLOCK #{name} #{xdim}".tap do |str|
9
+ def to_dcm(indented=false)
10
+ fmtstr = indented ? "%-26s%s %s" : "%s %s %d"
11
+
12
+ sprintf(fmtstr, type.upcase, name, xdim).tap do |str|
11
13
  str << " @ #{ydim}" if ydim != 1
12
14
  str << "\n"
13
15
  str << " LANGNAME #{description.enquote}\n" if description
@@ -15,8 +17,8 @@ class Ecu
15
17
  str << " EINHEIT_W #{unit.enquote}\n" if unit
16
18
  value.each do |row|
17
19
  str << case row.first
18
- when Numeric then " WERT #{row.join(" ")}\n"
19
- when String then " TEXT #{row.map(&:enquote).join(" ")}\n"
20
+ when Numeric then " WERT #{row.join(" ")}\n"
21
+ when String then " TEXT #{row.map(&:enquote).join(" ")}\n"
20
22
  end
21
23
  end
22
24
  str << "END\n"
@@ -4,16 +4,18 @@ class Ecu
4
4
  %r{^KENNFELD\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)\s+(?<ydim>\d+)}
5
5
  end
6
6
 
7
- def to_dcm
8
- "#{type.upcase} #{name} #{xdim} #{ydim}\n".tap do |str|
7
+ def to_dcm(indented=false)
8
+ fmtstr = indented ? "%-26s%s %s %s\n" : "%s %s %d %d\n"
9
+
10
+ sprintf(fmtstr, type.upcase, name, xdim, ydim).tap do |str|
9
11
  str << " LANGNAME #{description.enquote}\n" if description
10
12
  str << " FUNKTION #{function}\n" if function
11
13
  str << " EINHEIT_X #{xunit.enquote}\n" if xunit
12
14
  str << " EINHEIT_Y #{yunit.enquote}\n" if yunit
13
15
  str << " EINHEIT_W #{unit.enquote}\n" if unit
14
16
  str << case xvalue.first
15
- when Numeric then " ST/X #{xvalue.join(" ")}\n"
16
- when String then " ST_TX/X #{xvalue.map(&:enquote).join(" ")}\n"
17
+ when Numeric then " ST/X #{xvalue.join(" ")}\n"
18
+ when String then " ST_TX/X #{xvalue.map(&:enquote).join(" ")}\n"
17
19
  end
18
20
  yvalue.each_with_index do |entry, idx|
19
21
  str << case entry
@@ -21,8 +23,8 @@ class Ecu
21
23
  when String then " ST_TX/Y #{entry.enquote}\n"
22
24
  end
23
25
  str << case value[idx].first
24
- when Numeric then " WERT #{value[idx].join(" ")}\n"
25
- when String then " TEXT #{value[idx].map(&:enquote).join(" ")}\n"
26
+ when Numeric then " WERT #{value[idx].join(" ")}\n"
27
+ when String then " TEXT #{value[idx].map(&:enquote).join(" ")}\n"
26
28
  end
27
29
  end
28
30
  str << "END\n"
@@ -4,19 +4,21 @@ class Ecu
4
4
  %r{^KENNLINIE\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)}
5
5
  end
6
6
 
7
- def to_dcm
8
- "#{type.upcase} #{name} #{xdim}\n".tap do |str|
7
+ def to_dcm(indented=false)
8
+ fmtstr = indented ? "%-26s%s %s\n" : "%s %s %d\n"
9
+
10
+ sprintf(fmtstr, type.upcase, name, xdim).tap do |str|
9
11
  str << " LANGNAME #{description.enquote}\n" if description
10
12
  str << " FUNKTION #{function}\n" if function
11
13
  str << " EINHEIT_X #{xunit.enquote}\n" if xunit
12
14
  str << " EINHEIT_W #{unit.enquote}\n" if unit
13
15
  str << case xvalue.first
14
- when Numeric then " ST/X #{xvalue.join(" ")}\n"
15
- when String then " ST_TX/X #{xvalue.map(&:enquote).join(" ")}\n"
16
+ when Numeric then " ST/X #{xvalue.join(" ")}\n"
17
+ when String then " ST_TX/X #{xvalue.map(&:enquote).join(" ")}\n"
16
18
  end
17
19
  str << case value.first
18
- when Numeric then " WERT #{value.join(" ")}\n"
19
- when String then " TEXT #{value.map(&:enquote).join(" ")}\n"
20
+ when Numeric then " WERT #{value.join(" ")}\n"
21
+ when String then " TEXT #{value.map(&:enquote).join(" ")}\n"
20
22
  end
21
23
  str << "END\n"
22
24
  end
@@ -73,7 +73,7 @@ class Ecu
73
73
  line.chomp.gsub(/[[:space:]]/, " ").rstrip
74
74
  end
75
75
 
76
- def to_dcm
76
+ def to_dcm(indented=false)
77
77
  out = []
78
78
 
79
79
  unless headers.empty?
@@ -86,7 +86,7 @@ class Ecu
86
86
  out += subheaders.map { "* " + _1 }.push("")
87
87
  end
88
88
 
89
- out += map(&:to_dcm)
89
+ out += map { _1.to_dcm(indented) }
90
90
 
91
91
  out.join("\n")
92
92
  end
@@ -39,9 +39,11 @@ class Ecu
39
39
  end
40
40
 
41
41
  def self.numeric_value(str)
42
- return str.to_f if str.match?(/^\d+\.$/)
43
-
44
- Float(str)
42
+ case str
43
+ in /^\d+$/ then str.to_i
44
+ in /^\d+\.$/ then str.to_f
45
+ else Float(str)
46
+ end
45
47
  end
46
48
 
47
49
  end
@@ -4,14 +4,16 @@ class Ecu
4
4
  %r{STUETZSTELLENVERTEILUNG\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)}
5
5
  end
6
6
 
7
- def to_dcm
8
- "#{type.upcase} #{name} #{xdim}\n".tap do |str|
7
+ def to_dcm(indented=false)
8
+ fmtstr = indented ? "%-26s%s %s\n" : "%s %s %d\n"
9
+
10
+ sprintf(fmtstr, type.upcase, name, xdim).tap do |str|
9
11
  str << " LANGNAME #{description.enquote}\n" if description
10
12
  str << " FUNKTION #{function}\n" if function
11
13
  str << " EINHEIT_X #{xunit.enquote}\n" if xunit
12
14
  str << case xvalue.first
13
- when Numeric then " ST/X #{xvalue.join(" ")}\n"
14
- when String then " ST_TX/X #{xvalue.map(&:enquote).join(" ")}\n"
15
+ when Numeric then " ST/X #{xvalue.join(" ")}\n"
16
+ when String then " ST_TX/X #{xvalue.map(&:enquote).join(" ")}\n"
15
17
  end
16
18
  str << "END\n"
17
19
  end
data/lib/ecu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Ecu
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: automotive-ecu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Mueller