Class: Ecu::Label

Inherits:
Object
  • 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

#descriptionObject (readonly)

Returns the value of attribute description.



13
14
15
# File 'lib/ecu/labels/label.rb', line 13

def description
  @description
end

#functionObject (readonly)

Returns the value of attribute function.



13
14
15
# File 'lib/ecu/labels/label.rb', line 13

def function
  @function
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/ecu/labels/label.rb', line 13

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object



39
40
41
# File 'lib/ecu/labels/label.rb', line 39

def <=>(other)
  name <=> other.name if other.respond_to?(:name)
end

#==(other) ⇒ Object Also known as: eql?



56
57
58
59
60
61
62
63
64
65
# File 'lib/ecu/labels/label.rb', line 56

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



67
68
69
# File 'lib/ecu/labels/label.rb', line 67

def ===(other)
  name == other.name
end

#equality_propertiesObject



31
32
33
# File 'lib/ecu/labels/label.rb', line 31

def equality_properties
  fail NotImplementedError, "Must be implemented in child classes"
end

#hashObject



43
44
45
# File 'lib/ecu/labels/label.rb', line 43

def hash
  equality_properties.map { |p| self.public_send(p) }.hash
end

#init_error(message) ⇒ Object



15
16
17
18
19
# File 'lib/ecu/labels/label.rb', line 15

def init_error(message)
  fail ArgumentError, "Error creating #{name}: " +
    message + "\n" +
    inspect_instance_vars + "\n\n"
end

#inspect_instance_varsObject



21
22
23
24
25
# File 'lib/ecu/labels/label.rb', line 21

def inspect_instance_vars
  instance_variables
    .map { "#{_1} = #{instance_variable_get(_1)}" }
    .join("\n")
end

#match(selector) ⇒ Object



71
72
73
74
75
# File 'lib/ecu/labels/label.rb', line 71

def match(selector)
  %i(name function description).any? do |property|
    self.public_send(property) && self.public_send(property).match(selector)
  end
end

#propertiesObject



35
36
37
# File 'lib/ecu/labels/label.rb', line 35

def properties
  fail NotImplementedError, "Must be implemented in child classes"
end

#to_dcmObject



3
4
5
# File 'lib/ecu/interfaces/dcm/label.rb', line 3

def to_dcm
  fail "To be defined by child classes"
end

#to_hObject



47
48
49
# File 'lib/ecu/labels/label.rb', line 47

def to_h
  properties.zip(properties.map { |p| instance_variable_get("@#{p}".to_sym) }).to_h
end

#to_labObject



3
4
5
# File 'lib/ecu/interfaces/lab/label.rb', line 3

def to_lab
  "#{name};#{description}"
end

#typeObject



27
28
29
# File 'lib/ecu/labels/label.rb', line 27

def type
  self.class.name.split('::').last
end

#valuestats(value, show_avg: false) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/ecu/labels/label.rb', line 77

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



51
52
53
54
# File 'lib/ecu/labels/label.rb', line 51

def with(hash={})
  return self if hash.empty?
  self.class.new(**to_h.merge(hash))
end