Class: Ecu::Label
- Inherits:
-
Object
show all
- Defined in:
- lib/ecu/labels/label.rb,
lib/ecu/interfaces/dcm/label.rb,
lib/ecu/interfaces/lab/label.rb
Constant Summary
collapse
- BYTESIZE =
{ number: 4,
string: 25 }
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
14
15
16
|
# File 'lib/ecu/labels/label.rb', line 14
def description
@description
end
|
#function ⇒ Object
Returns the value of attribute function.
14
15
16
|
# File 'lib/ecu/labels/label.rb', line 14
def function
@function
end
|
#name ⇒ Object
Returns the value of attribute name.
14
15
16
|
# File 'lib/ecu/labels/label.rb', line 14
def name
@name
end
|
Instance Method Details
#<=>(other) ⇒ Object
40
41
42
|
# File 'lib/ecu/labels/label.rb', line 40
def <=>(other)
name <=> other.name if other.respond_to?(:name)
end
|
#==(other) ⇒ Object
Also known as:
eql?
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/ecu/labels/label.rb', line 57
def ==(other)
return false unless other.instance_of?(self.class)
equality_properties.all? do |p|
if %i(value xvalue yvalue).include?(p)
ValueComparison.new(self.public_send(p), other.public_send(p)).eql?
else
self.public_send(p) == other.public_send(p)
end
end
end
|
#===(other) ⇒ Object
68
69
70
|
# File 'lib/ecu/labels/label.rb', line 68
def ===(other)
name == other.name
end
|
#equality_properties ⇒ Object
32
33
34
|
# File 'lib/ecu/labels/label.rb', line 32
def equality_properties
fail NotImplementedError, "Must be implemented in child classes"
end
|
#hash ⇒ Object
44
45
46
|
# File 'lib/ecu/labels/label.rb', line 44
def hash
equality_properties.map { |p| self.public_send(p) }.hash
end
|
#init_error(message) ⇒ Object
16
17
18
19
20
|
# File 'lib/ecu/labels/label.rb', line 16
def init_error(message)
fail ArgumentError, "Error creating #{name}: " +
message + "\n" +
inspect_instance_vars + "\n\n"
end
|
#inspect_instance_vars ⇒ Object
22
23
24
25
26
|
# File 'lib/ecu/labels/label.rb', line 22
def inspect_instance_vars
instance_variables
.map { "#{_1} = #{instance_variable_get(_1)}" }
.join("\n")
end
|
#match(selector) ⇒ Object
72
73
74
75
76
|
# File 'lib/ecu/labels/label.rb', line 72
def match(selector)
%i(name function description).any? do |property|
self.public_send(property) && self.public_send(property).match(selector)
end
end
|
#properties ⇒ Object
36
37
38
|
# File 'lib/ecu/labels/label.rb', line 36
def properties
fail NotImplementedError, "Must be implemented in child classes"
end
|
#to_dcm ⇒ Object
3
4
5
|
# File 'lib/ecu/interfaces/dcm/label.rb', line 3
def to_dcm
fail "To be defined by child classes"
end
|
#to_h ⇒ Object
48
49
50
|
# File 'lib/ecu/labels/label.rb', line 48
def to_h
properties.zip(properties.map { |p| instance_variable_get("@#{p}".to_sym) }).to_h
end
|
#to_lab ⇒ Object
3
4
5
|
# File 'lib/ecu/interfaces/lab/label.rb', line 3
def to_lab
"#{name};#{description}"
end
|
#type ⇒ Object
28
29
30
|
# File 'lib/ecu/labels/label.rb', line 28
def type
self.class.name.split('::').last
end
|
#valuestats(value, show_avg: false) ⇒ Object
78
79
80
81
82
83
84
85
86
|
# File 'lib/ecu/labels/label.rb', line 78
def valuestats(value, show_avg: false)
value = [value].flatten
min, avg, max = value.min, value.avg.round(1), value.max
if show_avg
"[#{min};~#{avg};#{max}]"
else
"[#{min};#{max}]"
end
end
|
#with(hash = {}) ⇒ Object
52
53
54
55
|
# File 'lib/ecu/labels/label.rb', line 52
def with(hash={})
return self if hash.empty?
self.class.new(**to_h.merge(hash))
end
|