Method: LadderDrive::PlcDevice#initialize

Defined in:
lib/ladder_drive/plc_device.rb

#initialize(a, b = nil) ⇒ PlcDevice

Returns a new instance of PlcDevice.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ladder_drive/plc_device.rb', line 53

def initialize a, b = nil
  @suffix = nil
  @value = 0
  case a
  when Integer
    @suffix = ESC_SUFFIXES[a]
    @number = b
  when String, Symbol
    a = a.to_s # convert to string if it's a symbol
    if b
      @suffix = a.upcase
      @number = b
    else
      /([A-Z]+)?([0-9A-F]+)/i =~ a
      @suffix = ($1 || "").upcase
      case number_type
      when NUMBER_TYPE_DEC_HEX
        n = $2.to_i
        @number = (n / 100) * 16 + (n % 100)
      when NUMBER_TYPE_HEX
        @number = $2.to_i(16)
      else
        @number = $2.to_i
      end
    end
  end
end