Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/netlinx/erb/helpers.rb

Overview

:nodoc:

Other collapse

Instance Method Details

#remove_comma_after_last_itemObject

Intended for initializing struct constants.



368
369
370
# File 'lib/netlinx/erb/helpers.rb', line 368

def remove_comma_after_last_item
  self.gsub(/(?<=\}),(.*?)\z/, ' \1')
end

#to_hiqnet(sv = nil) ⇒ Object

Convert a string to a HiQnet address struct.

Can include state variable.

Examples:

'0x100203000103'.to_hiqnet(0x0000)
# Generates:
{$10, $02, $03, $00, $01, $03, $00, $00},

Parameters:

  • sv (String, Integer, nil) (defaults to: nil)

    , state variable



380
381
382
383
384
385
386
387
# File 'lib/netlinx/erb/helpers.rb', line 380

def to_hiqnet sv = nil
  sv ||= ''
  sv = sv.is_a?(Fixnum) ? sv.to_s(16) : sv.to_s
  sv = sv.rjust(4, '0') unless sv.empty?
    
  address = self + sv
  "{#{address.gsub(/\A0x/, '').upcase.scan(/../).map {|s| '$' + s}.join(', ')}},"
end