Class: Ecu::Festwert
- Inherits:
-
Label
- Object
- Label
- Ecu::Festwert
show all
- Defined in:
- lib/ecu/labels/festwert.rb,
lib/ecu/interfaces/dcm/festwert.rb,
lib/ecu/interfaces/mfile/festwert.rb
Constant Summary
Constants inherited
from Label
Label::BYTESIZE
Instance Attribute Summary collapse
Attributes inherited from Label
#description, #function, #name
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Label
#<=>, #==, #===, from_dcm, from_lab, #hash, #init_error, #match, #to_h, #to_lab, #type, #valuestats, #with
Constructor Details
#initialize(name:, value:, unit: nil, function: nil, description: nil) ⇒ Festwert
Returns a new instance of Festwert.
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/ecu/labels/festwert.rb', line 8
def initialize(name:,
value:,
unit: nil,
function: nil,
description: nil)
@name = name
@value = value.is_a?(Array) ? value.first : value
@unit = unit
@function = function
@description = description
end
|
Instance Attribute Details
#unit ⇒ Object
Returns the value of attribute unit.
6
7
8
|
# File 'lib/ecu/labels/festwert.rb', line 6
def unit
@unit
end
|
#value ⇒ Object
Returns the value of attribute value.
6
7
8
|
# File 'lib/ecu/labels/festwert.rb', line 6
def value
@value
end
|
Class Method Details
3
4
5
|
# File 'lib/ecu/interfaces/dcm/festwert.rb', line 3
def self.
%r{FESTWERT\s+(?<name>[A-Za-z0-9\._]+)}
end
|
Instance Method Details
#bytesize ⇒ Object
26
27
28
|
# File 'lib/ecu/labels/festwert.rb', line 26
def bytesize
BYTESIZE[:number]
end
|
#equality_properties ⇒ Object
54
55
56
|
# File 'lib/ecu/labels/festwert.rb', line 54
def equality_properties
[:name, :value]
end
|
#properties ⇒ Object
50
51
52
|
# File 'lib/ecu/labels/festwert.rb', line 50
def properties
[:name, :value, :unit, :function, :description]
end
|
#round_to(n) ⇒ Object
20
21
22
23
24
|
# File 'lib/ecu/labels/festwert.rb', line 20
def round_to(n)
return self unless value.is_a?(Numeric)
self.with \
value: value.round(n)
end
|
#to_dcm(indented = false) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/ecu/interfaces/dcm/festwert.rb', line 7
def to_dcm(indented=false)
fmtstr = indented ? "%-25s%s\n" : "%s %s\n"
sprintf(fmtstr, type.upcase, name).tap do |str|
str << " LANGNAME #{description.enquote}\n" if description
str << " FUNKTION #{function}\n" if function
str << " EINHEIT_W #{unit.enquote}\n" if unit
str << case value
when Numeric then " WERT #{value}\n"
when String then " TEXT #{value.enquote}\n"
end
str << "END\n"
end
end
|
#to_mfile ⇒ Object
3
4
5
6
7
8
|
# File 'lib/ecu/interfaces/mfile/festwert.rb', line 3
def to_mfile
case value
when Numeric then "#{name} = #{value};\n"
when String then "#{name} = '#{value}';\n"
end
end
|
#to_s(detail: false) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/ecu/labels/festwert.rb', line 30
def to_s(detail: false)
if detail == :justvalue
value.to_s
elsif detail == :value
"#{name}: #{value}"
elsif detail == :onelinefull
"#{name}: #{to_s(detail: :oneline)}"
elsif detail == :oneline
"#{value}"
elsif detail
" \#{name}: \#{type}\n Value: \#{value}\n Unit: \"\#{unit}\"\n EOS\n else\n \"\#{name}: \#{type}\"\n end\nend\n"
|