Class: Scjson::Types::InvokeProps

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) ⇒ InvokeProps

Instantiate a new InvokeProps object.

Parameters:

  • kwargs (Hash)

    Optional keyword overrides.



1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File 'lib/scjson/types.rb', line 1088

def initialize(**kwargs)
  @content = kwargs.fetch(:content, [])
  @param = kwargs.fetch(:param, [])
  @finalize = kwargs.fetch(:finalize, [])
  @other_element = kwargs.fetch(:other_element, [])
  @type_value = kwargs.fetch(:type_value, 'scxml')
  @typeexpr = kwargs.fetch(:typeexpr, nil)
  @src = kwargs.fetch(:src, nil)
  @srcexpr = kwargs.fetch(:srcexpr, nil)
  @id = kwargs.fetch(:id, nil)
  @idlocation = kwargs.fetch(:idlocation, nil)
  @namelist = kwargs.fetch(:namelist, nil)
  @autoforward = kwargs.fetch(:autoforward, BooleanDatatypeProps::FALSE)
  @other_attributes = kwargs.fetch(:other_attributes, {})
end

Instance Attribute Details

#autoforwardObject

Returns the value of attribute autoforward.



1085
1086
1087
# File 'lib/scjson/types.rb', line 1085

def autoforward
  @autoforward
end

#contentObject

Returns the value of attribute content.



1085
1086
1087
# File 'lib/scjson/types.rb', line 1085

def content
  @content
end

#finalizeObject

Returns the value of attribute finalize.



1085
1086
1087
# File 'lib/scjson/types.rb', line 1085

def finalize
  @finalize
end

#idObject

Returns the value of attribute id.



1085
1086
1087
# File 'lib/scjson/types.rb', line 1085

def id
  @id
end

#idlocationObject

Returns the value of attribute idlocation.



1085
1086
1087
# File 'lib/scjson/types.rb', line 1085

def idlocation
  @idlocation
end

#namelistObject

Returns the value of attribute namelist.



1085
1086
1087
# File 'lib/scjson/types.rb', line 1085

def namelist
  @namelist
end

#other_attributesObject

Returns the value of attribute other_attributes.



1085
1086
1087
# File 'lib/scjson/types.rb', line 1085

def other_attributes
  @other_attributes
end

#other_elementObject

Returns the value of attribute other_element.



1085
1086
1087
# File 'lib/scjson/types.rb', line 1085

def other_element
  @other_element
end

#paramObject

Returns the value of attribute param.



1085
1086
1087
# File 'lib/scjson/types.rb', line 1085

def param
  @param
end

#srcObject

Returns the value of attribute src.



1085
1086
1087
# File 'lib/scjson/types.rb', line 1085

def src
  @src
end

#srcexprObject

Returns the value of attribute srcexpr.



1085
1086
1087
# File 'lib/scjson/types.rb', line 1085

def srcexpr
  @srcexpr
end

#type_valueObject

Returns the value of attribute type_value.



1085
1086
1087
# File 'lib/scjson/types.rb', line 1085

def type_value
  @type_value
end

#typeexprObject

Returns the value of attribute typeexpr.



1085
1086
1087
# File 'lib/scjson/types.rb', line 1085

def typeexpr
  @typeexpr
end

Class Method Details

.from_hash(data) ⇒ InvokeProps

Build an instance from a Hash representation.

Parameters:

  • data (Hash)

    Canonical hash representation.

Returns:

Raises:

  • (ArgumentError)


1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
# File 'lib/scjson/types.rb', line 1107

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

  normalized = data.transform_keys(&:to_s)
  kwargs = {}
  kwargs[:content] = Array(normalized.fetch('content', [])).map { |item| ContentProps.from_hash(item) }
  kwargs[:param] = Array(normalized.fetch('param', [])).map { |item| ParamProps.from_hash(item) }
  kwargs[:finalize] = Array(normalized.fetch('finalize', [])).map { |item| FinalizeProps.from_hash(item) }
  kwargs[:other_element] = Array(normalized.fetch('other_element', []))
  kwargs[:type_value] = normalized.fetch('type_value', 'scxml')
  kwargs[:typeexpr] = normalized.fetch('typeexpr', nil)
  kwargs[:src] = normalized.fetch('src', nil)
  kwargs[:srcexpr] = normalized.fetch('srcexpr', nil)
  kwargs[:id] = normalized.fetch('id', nil)
  kwargs[:idlocation] = normalized.fetch('idlocation', nil)
  kwargs[:namelist] = normalized.fetch('namelist', nil)
  kwargs[:autoforward] = BooleanDatatypeProps.coerce(normalized.fetch('autoforward', BooleanDatatypeProps::FALSE))
  kwargs[:other_attributes] = normalized.fetch('other_attributes', {})
  new(**kwargs)
end

.from_json(json) ⇒ InvokeProps

Deserialize an instance from a JSON payload.

Parameters:

  • json (String)

    JSON document to decode.

Returns:



1131
1132
1133
1134
# File 'lib/scjson/types.rb', line 1131

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)


1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
# File 'lib/scjson/types.rb', line 1138

def to_hash
  {
    'content' => (@content || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item },
    'param' => (@param || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item },
    'finalize' => (@finalize || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item },
    'other_element' => @other_element,
    'type_value' => @type_value,
    'typeexpr' => @typeexpr,
    'src' => @src,
    'srcexpr' => @srcexpr,
    'id' => @id,
    'idlocation' => @idlocation,
    'namelist' => @namelist,
    'autoforward' => @autoforward,
    'other_attributes' => @other_attributes
  }
end

#to_json(*opts) ⇒ String

Serialize the object to JSON.

Parameters:

  • opts (Array)

    JSON generation options.

Returns:

  • (String)


1159
1160
1161
# File 'lib/scjson/types.rb', line 1159

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