class QRPC::Protocol::JsonRpc::Native::QrpcObject

QRPC JSON-RPC QRPC object. Extends the JsonRpcObjects::Generic::Object. See its documentation for additional methods.

@since 0.2.0

Constants

VERSION

Holds JSON-RPC version indication.

Public Class Methods

create(opts = { }) click to toggle source

Creates new QRPC JSON-RPC object.

@param [Hash] QRPC object optional arguments @return [QRPC::Protocol::QrpcObject] new instance

# File lib/qrpc/protocol/json-rpc/native/qrpc-object.rb, line 60
def self.create(opts = { })
    self::new(opts)
end

Public Instance Methods

check!() click to toggle source

Checks correctness of the object data.

# File lib/qrpc/protocol/json-rpc/native/qrpc-object.rb, line 68
def check!
    self.normalize!
    
    if (not @priority.nil?) and not (@priority.kind_of? Numeric)
        raise Exception::new("Priority is expected to be Numeric.")
    end
    
    if not (@notification.boolean?)
        raise Exception::new("Notification is expected to be Boolean.")
    end
end
output() click to toggle source

Renders data to output form. @return [Hash] with data of object

# File lib/qrpc/protocol/json-rpc/native/qrpc-object.rb, line 85
def output
    result = { 
        "version" => "1.0.2"
    }
    
    if not @priority.nil?
        result["priority"] = @priority
    end
    
    if not @client.nil?
        result["client"] = @client.to_s
    end
    
    if @notification.true?
        result["notification"] = @notification
    end
    
    return result
end

Protected Instance Methods

data=(value, mode = nil) click to toggle source

 Assigns data.

# File lib/qrpc/protocol/json-rpc/native/qrpc-object.rb, line 112
def data=(value, mode = nil)
    data = __convert_data(value, mode)
    
    @priority = data[:priority]
    @client = data[:client]
    @notification = data[:notification]
end
normalize!() click to toggle source

Converts data to standard (defined) format.

# File lib/qrpc/protocol/json-rpc/native/qrpc-object.rb, line 124
def normalize!
    if not @priority.nil?
        @priority = @priority.to_i
    end
    
    if @notification.nil?
        @notification = false
    end
end