class VidPid

Public Class Methods

new(*args) click to toggle source
# File lib/svi/vidpid.rb, line 5
def initialize *args
    raise ArgumentError, 'function shall accept 2 arguments max' if args.count > 2

    @vid, @pid = 0, 0

    if args.count == 1
        _args = args[0].to_s.split ':'

        raise ArgumentError, "Invalid string format of vid:pid - #{args[0].to_s}" if _args.count != 2

        args = _args
    end

    if args.count == 2
        self.vid = args[0]
        self.pid = args[1]
    end
end

Public Instance Methods

pid() click to toggle source
# File lib/svi/vidpid.rb, line 28
def pid
    @pid
end
pid=(product) click to toggle source
# File lib/svi/vidpid.rb, line 44
def pid= (product)
    if String === product
        i = product.to_i 16
    else
        i = product.to_i
    end

    raise ArgumentError, "Invalid product #{product}" if i < 0 || i > 65535

    @pid = i
end
to_s() click to toggle source
# File lib/svi/vidpid.rb, line 56
def to_s
    "#{@vid.to_s(16)}:#{@pid.to_s(16)}"
end
vid() click to toggle source
# File lib/svi/vidpid.rb, line 24
def vid
    @vid
end
vid=(vendor) click to toggle source
# File lib/svi/vidpid.rb, line 32
def vid= (vendor)
    if String === vendor
        i = vendor.to_i 16
    else
        i = vendor.to_i
    end

    raise ArgumentError, "Invalid vendor #{vendor}" if i < 0 || i > 65535

    @vid = i
end