automotive-ecu 0.3.1 → 0.3.2

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: 52253becc23cc2f6a9e2da39535fc6b7b7f9332ff42c09f5b547ffa32984eb9b
4
- data.tar.gz: 31454568e63eaafc261c4967422b35ddaa6582cdd4af99b24f9bd2e10dfa7698
3
+ metadata.gz: 4ad47ed36e2d54205a5c804187b85e2f2a7b91d73f2fc1bc548f691a87804c88
4
+ data.tar.gz: 2ab14530309248995b479e9dc4010bf61a83f767efd62ddf9b739686791aaae5
5
5
  SHA512:
6
- metadata.gz: 8bb7e3726537a3d979f06880ce13c8637fe22a458fe83eb72bfe73f9b7b650dfe82d80e1d343c791e14b2e0daccbd7ed36fca83942a0ee003d0b1a0644c4a250
7
- data.tar.gz: 95826e4c5797ec1a7ab7a990061671c07be15e23f32917e2b8a28d7f1b65a364ab820dfa29b361639e9e6d511d70257cbd7ffbce60d7b8e3433b336ed02468a5
6
+ metadata.gz: de3516033d423a95b0c813f3e22eed22a0195fbbf5c4d7b2dc6f3604d897d59bd4b7bc46f0b527651fa5f3c1ffecec4cc3642e3f1482033b0104154088abdb44
7
+ data.tar.gz: ebaf253e55c358547cb63ad4024a8bf0e90c6bb7a529b5ab30a9117593436aacd15d546bd226a5cf7a02156edfe2193c94e67f51e59fc9545c6b9688cd35b45b
@@ -48,12 +48,12 @@ class Ecu
48
48
 
49
49
  return if @scan.eos?
50
50
 
51
- case @scan.peek(1)
52
- when "\n", "\r" then @scan.skip(NEWLINE) && :NEWLINE
53
- when '"' then @scan.skip(QUOTED_TEXT) && :QUOTED_TEXT
54
- when '*' then @scan.skip(COMMENT) && :COMMENT
55
- when '@' then @scan.skip(DIMENSIONS_SEP) && :DIMENSIONS_SEP
56
- when '-', '+', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
51
+ case @doc.getbyte(@scan.pos)
52
+ when 10, 13 then @scan.skip(NEWLINE) && :NEWLINE # \n \r
53
+ when 34 then @scan.skip(QUOTED_TEXT) && :QUOTED_TEXT # "
54
+ when 42 then @scan.skip(COMMENT) && :COMMENT # *
55
+ when 64 then @scan.skip(DIMENSIONS_SEP) && :DIMENSIONS_SEP # @
56
+ when 43, 45, 46, 48..57 # + - . 0-9
57
57
  if @scan.skip(FLOAT) then :FLOAT
58
58
  elsif @scan.skip(INT) then :INT
59
59
  else @scan.getch; :UNKNOWN_CHAR
@@ -158,10 +158,8 @@ class Ecu
158
158
 
159
159
  def finish_label
160
160
  next_state(:POST_HEADER) do
161
- @properties
162
- .except(:displayname)
163
- .then { @constructor.new(**_1) }
164
- .tap { reset_label! }
161
+ @properties.delete(:displayname)
162
+ @constructor.new(**@properties).tap { reset_label! }
165
163
  end
166
164
  end
167
165
 
@@ -186,7 +184,12 @@ class Ecu
186
184
  next_state(newstate) do
187
185
  @key = KEY_MAPPING[key]
188
186
  @is_ary = ARY_PROPERTIES.include?(@key)
189
- @value = @is_ary ? [] : nil
187
+ if @is_ary
188
+ @properties[@key] ||= []
189
+ @value = @properties[@key] # alias: append_property writes directly to target
190
+ else
191
+ @value = nil
192
+ end
190
193
  end
191
194
  end
192
195
 
@@ -202,15 +205,10 @@ class Ecu
202
205
 
203
206
  def finish_property
204
207
  next_state(:LABEL_CONTENT) do
205
- if @properties.key?(@key)
206
- if @is_ary
207
- @properties[@key].concat(@value)
208
- else
209
- fail "Multiple property lines not allowed for #{@key}"
210
- end
211
- else
212
- @properties[@key] = @value
213
- end
208
+ next if @is_ary # values already in @properties[@key] via @value alias
209
+
210
+ fail "Multiple property lines not allowed for #{@key}" if @properties.key?(@key)
211
+ @properties[@key] = @value
214
212
  end
215
213
  end
216
214
 
@@ -7,10 +7,11 @@ class Ecu
7
7
  str << " LANGNAME #{description.enquote}\n" if description
8
8
  str << " FUNKTION #{function}\n" if function
9
9
  str << " EINHEIT_W #{unit.enquote}\n" if unit
10
- str << case value
11
- when Numeric then " WERT #{value}\n"
12
- when String then " TEXT #{value.enquote}\n"
13
- end
10
+ if value.is_a?(Numeric)
11
+ str << " WERT " << value.to_s << "\n"
12
+ else
13
+ str << " TEXT " << value.enquote << "\n"
14
+ end
14
15
  str << "END\n"
15
16
  end
16
17
  end
@@ -29,21 +29,23 @@ class Ecu
29
29
  end
30
30
 
31
31
  def to_dcm(indented=false)
32
- out = []
32
+ buf = String.new
33
33
 
34
34
  unless headers.empty?
35
- out += headers.map { "* " + _1 }.push("")
35
+ headers.each { buf << "* " << _1 << "\n" }
36
+ buf << "\n"
36
37
  end
37
38
 
38
- out << DCM_HEADER << ""
39
+ buf << DCM_HEADER << "\n"
39
40
 
40
41
  unless subheaders.empty?
41
- out += subheaders.map { "* " + _1 }.push("")
42
+ buf << "\n"
43
+ subheaders.each { buf << "* " << _1 << "\n" }
42
44
  end
43
45
 
44
- out += map { _1.to_dcm(indented) }
46
+ each { buf << "\n" << _1.to_dcm(indented) }
45
47
 
46
- out.join("\n")
48
+ buf
47
49
  end
48
50
  end
49
51
  end
data/lib/ecu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Ecu
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
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.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Mueller