Sha256: 3fcda9518760808093db147141efe820c2de20b179e07739b9da0e7fa87de88d

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

class Ecu
  class DcmPropertyParser

    def self.call(line)
      key, _, value = line.strip.partition(/\s+/)
      eval_property(key, value)
    end

    private

    def self.eval_property(key, value)
      case key
      when "ST/X"        then { xvalue:      numeric_array(value) }
      when "ST/Y"        then { yvalue:      numeric_array(value) }
      when "WERT"        then { value:       numeric_array(value) }
      when "ST_TX/X"     then { xvalue:      string_array(value) }
      when "ST_TX/Y"     then { yvalue:      string_array(value) }
      when "TEXT"        then { value:       string_array(value) }
      when "FUNKTION"    then { function:    value }
      when "EINHEIT_X"   then { xunit:       string_value(value) }
      when "EINHEIT_Y"   then { yunit:       string_value(value) }
      when "EINHEIT_W"   then { unit:        string_value(value) }
      when "LANGNAME"    then { description: string_value(value) }
      when "DISPLAYNAME" then { }
      else fail ArgumentError, "Unknown key #{key}"
      end
    end

    def self.string_value(str)
      str.delete_surrounding('"')
    end

    def self.numeric_array(str)
      str.split.map { Float(_1) }
    end

    def self.string_array(str)
      str.scan(/"([^"]*)"/).flatten
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
automotive-ecu-0.1.2 lib/ecu/interfaces/dcm/property_parser.rb