Class: Scjson::Types::FinalizeProps

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

Overview

Structured type for scjson elements.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ FinalizeProps

Instantiate a new FinalizeProps object.

Parameters:

  • kwargs (Hash)

    Optional keyword overrides.



731
732
733
734
735
736
737
738
739
740
741
742
# File 'lib/scjson/types.rb', line 731

def initialize(**kwargs)
  @other_element = kwargs.fetch(:other_element, [])
  @raise_value = kwargs.fetch(:raise_value, [])
  @if_value = kwargs.fetch(:if_value, [])
  @foreach = kwargs.fetch(:foreach, [])
  @send = kwargs.fetch(:send, [])
  @script = kwargs.fetch(:script, [])
  @assign = kwargs.fetch(:assign, [])
  @log = kwargs.fetch(:log, [])
  @cancel = kwargs.fetch(:cancel, [])
  @other_attributes = kwargs.fetch(:other_attributes, {})
end

Instance Attribute Details

#assignObject

Returns the value of attribute assign.



728
729
730
# File 'lib/scjson/types.rb', line 728

def assign
  @assign
end

#cancelObject

Returns the value of attribute cancel.



728
729
730
# File 'lib/scjson/types.rb', line 728

def cancel
  @cancel
end

#foreachObject

Returns the value of attribute foreach.



728
729
730
# File 'lib/scjson/types.rb', line 728

def foreach
  @foreach
end

#if_valueObject

Returns the value of attribute if_value.



728
729
730
# File 'lib/scjson/types.rb', line 728

def if_value
  @if_value
end

#logObject

Returns the value of attribute log.



728
729
730
# File 'lib/scjson/types.rb', line 728

def log
  @log
end

#other_attributesObject

Returns the value of attribute other_attributes.



728
729
730
# File 'lib/scjson/types.rb', line 728

def other_attributes
  @other_attributes
end

#other_elementObject

Returns the value of attribute other_element.



728
729
730
# File 'lib/scjson/types.rb', line 728

def other_element
  @other_element
end

#raise_valueObject

Returns the value of attribute raise_value.



728
729
730
# File 'lib/scjson/types.rb', line 728

def raise_value
  @raise_value
end

#scriptObject

Returns the value of attribute script.



728
729
730
# File 'lib/scjson/types.rb', line 728

def script
  @script
end

#sendObject

Returns the value of attribute send.



728
729
730
# File 'lib/scjson/types.rb', line 728

def send
  @send
end

Class Method Details

.from_hash(data) ⇒ FinalizeProps

Build an instance from a Hash representation.

Parameters:

  • data (Hash)

    Canonical hash representation.

Returns:

Raises:

  • (ArgumentError)


747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
# File 'lib/scjson/types.rb', line 747

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[:raise_value] = Array(normalized.fetch('raise_value', [])).map { |item| RaiseProps.from_hash(item) }
  kwargs[:if_value] = Array(normalized.fetch('if_value', [])).map { |item| IfProps.from_hash(item) }
  kwargs[:foreach] = Array(normalized.fetch('foreach', [])).map { |item| ForeachProps.from_hash(item) }
  kwargs[:send] = Array(normalized.fetch('send', [])).map { |item| SendProps.from_hash(item) }
  kwargs[:script] = Array(normalized.fetch('script', [])).map { |item| ScriptProps.from_hash(item) }
  kwargs[:assign] = Array(normalized.fetch('assign', [])).map { |item| AssignProps.from_hash(item) }
  kwargs[:log] = Array(normalized.fetch('log', [])).map { |item| LogProps.from_hash(item) }
  kwargs[:cancel] = Array(normalized.fetch('cancel', [])).map { |item| CancelProps.from_hash(item) }
  kwargs[:other_attributes] = normalized.fetch('other_attributes', {})
  new(**kwargs)
end

.from_json(json) ⇒ FinalizeProps

Deserialize an instance from a JSON payload.

Parameters:

  • json (String)

    JSON document to decode.

Returns:



768
769
770
771
# File 'lib/scjson/types.rb', line 768

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)


775
776
777
778
779
780
781
782
783
784
785
786
787
788
# File 'lib/scjson/types.rb', line 775

def to_hash
  {
    'other_element' => @other_element,
    'raise_value' => (@raise_value || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item },
    'if_value' => (@if_value || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item },
    'foreach' => (@foreach || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item },
    'send' => (@send || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item },
    'script' => (@script || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item },
    'assign' => (@assign || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item },
    'log' => (@log || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item },
    'cancel' => (@cancel || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item },
    'other_attributes' => @other_attributes
  }
end

#to_json(*opts) ⇒ String

Serialize the object to JSON.

Parameters:

  • opts (Array)

    JSON generation options.

Returns:

  • (String)


793
794
795
# File 'lib/scjson/types.rb', line 793

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