Class: Ecu::Festwerteblock
- Inherits:
-
Label
- Object
- Label
- Ecu::Festwerteblock
show all
- Defined in:
- lib/ecu/labels/festwerteblock.rb,
lib/ecu/interfaces/dcm/festwerteblock.rb,
lib/ecu/interfaces/mfile/festwerteblock.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:, xdim:, ydim: 1, value:, unit: nil, function: nil, description: nil) ⇒ Festwerteblock
Returns a new instance of Festwerteblock.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/ecu/labels/festwerteblock.rb', line 8
def initialize(name:,
xdim:,
ydim: 1,
value:,
unit: nil,
function: nil,
description: nil)
value = reshape_if_needed(value, xdim, ydim)
ydim = ydim == 0 ? 1 : ydim
@name = name
@xdim = xdim
@ydim = ydim
@value = value
@unit = unit
@function = function
@description = description
init_error "Dimensions for value don't match ydim" if value.size != ydim
init_error "Dimensions for value don't match xdim" if value.any? { |row| row.is_a?(Array) && row.size != xdim }
end
|
Instance Attribute Details
#unit ⇒ Object
Returns the value of attribute unit.
6
7
8
|
# File 'lib/ecu/labels/festwerteblock.rb', line 6
def unit
@unit
end
|
#value ⇒ Object
Returns the value of attribute value.
6
7
8
|
# File 'lib/ecu/labels/festwerteblock.rb', line 6
def value
@value
end
|
#xdim ⇒ Object
Returns the value of attribute xdim.
6
7
8
|
# File 'lib/ecu/labels/festwerteblock.rb', line 6
def xdim
@xdim
end
|
#ydim ⇒ Object
Returns the value of attribute ydim.
6
7
8
|
# File 'lib/ecu/labels/festwerteblock.rb', line 6
def ydim
@ydim
end
|
Class Method Details
5
6
7
|
# File 'lib/ecu/interfaces/dcm/festwerteblock.rb', line 5
def self.
%r{FESTWERTEBLOCK\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)(?:\s+@\s+(?<ydim>\d+))?}
end
|
Instance Method Details
#bytesize ⇒ Object
35
36
37
|
# File 'lib/ecu/labels/festwerteblock.rb', line 35
def bytesize
xdim * ydim * BYTESIZE[:number]
end
|
#equality_properties ⇒ Object
65
66
67
|
# File 'lib/ecu/labels/festwerteblock.rb', line 65
def equality_properties
[:name, :value]
end
|
#properties ⇒ Object
61
62
63
|
# File 'lib/ecu/labels/festwerteblock.rb', line 61
def properties
[:name, :xdim, :ydim, :value, :unit, :function, :description]
end
|
#round_to(n) ⇒ Object
29
30
31
32
33
|
# File 'lib/ecu/labels/festwerteblock.rb', line 29
def round_to(n)
return self if value.any? { |row| row.any? { |e| e.is_a?(String) }}
self.with \
value: value.map { |row| row.map { |x| x.round(n) }}
end
|
#to_dcm ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/ecu/interfaces/dcm/festwerteblock.rb', line 9
def to_dcm
"FESTWERTEBLOCK #{name} #{xdim}".tap do |str|
str << " @ #{ydim}" if ydim != 1
str << "\n"
str << " LANGNAME #{description.enquote}\n" if description
str << " FUNKTION #{function}\n" if function
str << " EINHEIT_W #{unit.enquote}\n" if unit
value.each do |row|
str << case row.first
when Numeric then " WERT #{row.join(" ")}\n"
when String then " TEXT #{row.map(&:enquote).join(" ")}\n"
end
end
str << "END\n"
end
end
|
#to_mfile ⇒ Object
3
4
5
6
7
8
9
10
|
# File 'lib/ecu/interfaces/mfile/festwerteblock.rb', line 3
def to_mfile
"#{name} = [\n".tap do |str|
value.each do |row|
str << row.join(" ").indent << "\n"
end
str << "];\n"
end
end
|
#to_s(detail: false) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/ecu/labels/festwerteblock.rb', line 39
def to_s(detail: false)
if detail == :value
"#{name}:\n#{to_s(detail: :justvalue)}"
elsif detail == :justvalue
ValuePrinter.call(self)
elsif detail == :onelinefull
"#{name} #{to_s(detail: :oneline)}"
elsif detail == :oneline
"(#{xdim}x#{ydim}) Z: #{valuestats(value, show_avg: true)}"
else
"#{name}: #{xdim}x#{ydim} #{type}".tap do |str|
if detail
str << "\n"
str << " Unit: \"#{unit}\"\n"
str << " Value:\n"
str << ValuePrinter.call(self).indent(4)
str << "\n"
end
end
end
end
|