Sha256: 87da3fe92914b48ce40d02d0b9e2b73b07e7d714272e498bf41ddcd06e74f4b8

Contents?: true

Size: 1.17 KB

Versions: 11

Compression:

Stored size: 1.17 KB

Contents

require_relative "label"

class Ecu
  class Festwert < Label

    attr_reader :value, :unit

    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

    def round_to(n)
      return self unless value.is_a?(Numeric)
      self.with \
        value: value.round(n)
    end

    def bytesize
      BYTESIZE[:number]
    end

    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
        <<~EOS
        #{name}: #{type}
          Value: #{value}
          Unit: "#{unit}"
        EOS
      else
        "#{name}: #{type}"
      end
    end

    def properties
      [:name, :value, :unit, :function, :description]
    end

    def equality_properties
      [:name, :value]
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
automotive-ecu-0.1.10 lib/ecu/labels/festwert.rb
automotive-ecu-0.1.9 lib/ecu/labels/festwert.rb
automotive-ecu-0.1.8 lib/ecu/labels/festwert.rb
automotive-ecu-0.1.7 lib/ecu/labels/festwert.rb
automotive-ecu-0.1.6 lib/ecu/labels/festwert.rb
automotive-ecu-0.1.5 lib/ecu/labels/festwert.rb
automotive-ecu-0.1.4 lib/ecu/labels/festwert.rb
automotive-ecu-0.1.3 lib/ecu/labels/festwert.rb
automotive-ecu-0.1.2 lib/ecu/labels/festwert.rb
automotive-ecu-0.1.1 lib/ecu/labels/festwert.rb
automotive-ecu-0.1.0 lib/ecu/labels/festwert.rb