Class: Scjson::Types::CancelProps

Inherits:
Object
  • Object
show all
Defined in:
lib/scjson/types.rb

Overview

cancel a pending ‘<send>` operation.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ CancelProps

Instantiate a new CancelProps object.

Parameters:

  • kwargs (Hash)

    Optional keyword overrides.



293
294
295
296
297
298
# File 'lib/scjson/types.rb', line 293

def initialize(**kwargs)
  @other_element = kwargs.fetch(:other_element, [])
  @sendid = kwargs.fetch(:sendid, nil)
  @sendidexpr = kwargs.fetch(:sendidexpr, nil)
  @other_attributes = kwargs.fetch(:other_attributes, {})
end

Instance Attribute Details

#other_attributesObject

Returns the value of attribute other_attributes.



290
291
292
# File 'lib/scjson/types.rb', line 290

def other_attributes
  @other_attributes
end

#other_elementObject

Returns the value of attribute other_element.



290
291
292
# File 'lib/scjson/types.rb', line 290

def other_element
  @other_element
end

#sendidObject

Returns the value of attribute sendid.



290
291
292
# File 'lib/scjson/types.rb', line 290

def sendid
  @sendid
end

#sendidexprObject

Returns the value of attribute sendidexpr.



290
291
292
# File 'lib/scjson/types.rb', line 290

def sendidexpr
  @sendidexpr
end

Class Method Details

.from_hash(data) ⇒ CancelProps

Build an instance from a Hash representation.

Parameters:

  • data (Hash)

    Canonical hash representation.

Returns:

Raises:

  • (ArgumentError)


303
304
305
306
307
308
309
310
311
312
313
# File 'lib/scjson/types.rb', line 303

def self.from_hash(data)
  raise ArgumentError, 'Expected Hash' unless data.is_a?(Hash)

  normalized = data.transform_keys(&:to_s)
  kwargs = {}
  kwargs[:other_element] = Array(normalized.fetch('other_element', []))
  kwargs[:sendid] = normalized.fetch('sendid', nil)
  kwargs[:sendidexpr] = normalized.fetch('sendidexpr', nil)
  kwargs[:other_attributes] = normalized.fetch('other_attributes', {})
  new(**kwargs)
end

.from_json(json) ⇒ CancelProps

Deserialize an instance from a JSON payload.

Parameters:

  • json (String)

    JSON document to decode.

Returns:



318
319
320
321
# File 'lib/scjson/types.rb', line 318

def self.from_json(json)
  parsed = JSON.parse(json)
  from_hash(parsed)
end

Instance Method Details

#to_hashHash

Convert the object to a Hash suitable for JSON serialization.

Returns:

  • (Hash)


325
326
327
328
329
330
331
332
# File 'lib/scjson/types.rb', line 325

def to_hash
  {
    'other_element' => @other_element,
    'sendid' => @sendid,
    'sendidexpr' => @sendidexpr,
    'other_attributes' => @other_attributes
  }
end

#to_json(*opts) ⇒ String

Serialize the object to JSON.

Parameters:

  • opts (Array)

    JSON generation options.

Returns:

  • (String)


337
338
339
# File 'lib/scjson/types.rb', line 337

def to_json(*opts)
  JSON.generate(to_hash, *opts)
end