Class: Ecu::Stuetzstellenverteilung

Inherits:
Label
  • Object
show all
Defined in:
lib/ecu/labels/stuetzstellenverteilung.rb,
lib/ecu/interfaces/dcm/stuetzstellenverteilung.rb,
lib/ecu/interfaces/mfile/stuetzstellenverteilung.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:, xvalue:, xunit: nil, function: nil, description: nil) ⇒ Stuetzstellenverteilung

Returns a new instance of Stuetzstellenverteilung.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ecu/labels/stuetzstellenverteilung.rb', line 8

def initialize(name:,
               xdim:,
               xvalue:,
               xunit: nil,
               function: nil,
               description: nil)
  @name        = name
  @xdim        = xdim
  @xvalue      = xvalue
  @xunit       = xunit
  @function    = function
  @description = description

  init_error "Dimensions for xvalue don't match xdim" if xvalue.size != xdim
end

Instance Attribute Details

#xdimObject (readonly)

Returns the value of attribute xdim.



6
7
8
# File 'lib/ecu/labels/stuetzstellenverteilung.rb', line 6

def xdim
  @xdim
end

#xunitObject (readonly)

Returns the value of attribute xunit.



6
7
8
# File 'lib/ecu/labels/stuetzstellenverteilung.rb', line 6

def xunit
  @xunit
end

#xvalueObject (readonly)

Returns the value of attribute xvalue.



6
7
8
# File 'lib/ecu/labels/stuetzstellenverteilung.rb', line 6

def xvalue
  @xvalue
end

Class Method Details

.dcm_headerObject



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

def self.dcm_header
  %r{STUETZSTELLENVERTEILUNG\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)}
end

Instance Method Details

#bytesizeObject



30
31
32
# File 'lib/ecu/labels/stuetzstellenverteilung.rb', line 30

def bytesize
  xdim * BYTESIZE[:number]
end

#equality_propertiesObject



60
61
62
# File 'lib/ecu/labels/stuetzstellenverteilung.rb', line 60

def equality_properties
  [:name, :xvalue]
end

#propertiesObject



56
57
58
# File 'lib/ecu/labels/stuetzstellenverteilung.rb', line 56

def properties
  [:name, :xdim, :xvalue, :xunit, :function, :description]
end

#round_to(n) ⇒ Object



24
25
26
27
28
# File 'lib/ecu/labels/stuetzstellenverteilung.rb', line 24

def round_to(n)
  return self unless xvalue.all? { |x| x.is_a?(Numeric) }
  self.with \
    xvalue: xvalue.map { |x| x.round(n) }
end

#to_dcmObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ecu/interfaces/dcm/stuetzstellenverteilung.rb', line 7

def to_dcm
  "#{type.upcase} #{name} #{xdim}\n".tap do |str|
    str << "  LANGNAME #{description.enquote}\n" if description
    str << "  FUNKTION #{function}\n"            if function
    str << "  EINHEIT_X #{xunit.enquote}\n"      if xunit
    str << case xvalue.first
    when Numeric then "  ST/X #{xvalue.join(" ")}\n"
    when String then  "  ST_TX/X #{xvalue.map(&:enquote).join(" ")}\n"
    end
    str << "END\n"
  end
end

#to_mfileObject



3
4
5
# File 'lib/ecu/interfaces/mfile/stuetzstellenverteilung.rb', line 3

def to_mfile
  "#{name} = [#{xvalue.join("  ")}];\n"
end

#to_s(detail: false) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ecu/labels/stuetzstellenverteilung.rb', line 34

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}x1) X: #{valuestats(xvalue)}"
  else
    "#{name}: #{@xdim}x1 #{type}".tap do |str|
      if detail
        str << "\n"
        str << "  Unit: \"#{xunit}\"\n"
        str << "  Value:\n"
        str << ValuePrinter.call(self).indent(4)
        str << "\n"
      end
    end
  end
end