Class: Scjson::Types::InvokeProps
- Inherits:
-
Object
- Object
- Scjson::Types::InvokeProps
- Defined in:
- lib/scjson/types.rb
Overview
Structured type for scjson elements.
Instance Attribute Summary collapse
-
#autoforward ⇒ Object
Returns the value of attribute autoforward.
-
#content ⇒ Object
Returns the value of attribute content.
-
#finalize ⇒ Object
Returns the value of attribute finalize.
-
#id ⇒ Object
Returns the value of attribute id.
-
#idlocation ⇒ Object
Returns the value of attribute idlocation.
-
#namelist ⇒ Object
Returns the value of attribute namelist.
-
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
-
#other_element ⇒ Object
Returns the value of attribute other_element.
-
#param ⇒ Object
Returns the value of attribute param.
-
#src ⇒ Object
Returns the value of attribute src.
-
#srcexpr ⇒ Object
Returns the value of attribute srcexpr.
-
#type_value ⇒ Object
Returns the value of attribute type_value.
-
#typeexpr ⇒ Object
Returns the value of attribute typeexpr.
Class Method Summary collapse
-
.from_hash(data) ⇒ InvokeProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ InvokeProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ InvokeProps
constructor
Instantiate a new InvokeProps object.
-
#to_hash ⇒ Hash
Convert the object to a Hash suitable for JSON serialization.
-
#to_json(*opts) ⇒ String
Serialize the object to JSON.
Constructor Details
#initialize(**kwargs) ⇒ InvokeProps
Instantiate a new InvokeProps object.
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
#autoforward ⇒ Object
Returns the value of attribute autoforward.
1085 1086 1087 |
# File 'lib/scjson/types.rb', line 1085 def autoforward @autoforward end |
#content ⇒ Object
Returns the value of attribute content.
1085 1086 1087 |
# File 'lib/scjson/types.rb', line 1085 def content @content end |
#finalize ⇒ Object
Returns the value of attribute finalize.
1085 1086 1087 |
# File 'lib/scjson/types.rb', line 1085 def finalize @finalize end |
#id ⇒ Object
Returns the value of attribute id.
1085 1086 1087 |
# File 'lib/scjson/types.rb', line 1085 def id @id end |
#idlocation ⇒ Object
Returns the value of attribute idlocation.
1085 1086 1087 |
# File 'lib/scjson/types.rb', line 1085 def idlocation @idlocation end |
#namelist ⇒ Object
Returns the value of attribute namelist.
1085 1086 1087 |
# File 'lib/scjson/types.rb', line 1085 def namelist @namelist end |
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
1085 1086 1087 |
# File 'lib/scjson/types.rb', line 1085 def other_attributes @other_attributes end |
#other_element ⇒ Object
Returns the value of attribute other_element.
1085 1086 1087 |
# File 'lib/scjson/types.rb', line 1085 def other_element @other_element end |
#param ⇒ Object
Returns the value of attribute param.
1085 1086 1087 |
# File 'lib/scjson/types.rb', line 1085 def param @param end |
#src ⇒ Object
Returns the value of attribute src.
1085 1086 1087 |
# File 'lib/scjson/types.rb', line 1085 def src @src end |
#srcexpr ⇒ Object
Returns the value of attribute srcexpr.
1085 1086 1087 |
# File 'lib/scjson/types.rb', line 1085 def srcexpr @srcexpr end |
#type_value ⇒ Object
Returns the value of attribute type_value.
1085 1086 1087 |
# File 'lib/scjson/types.rb', line 1085 def type_value @type_value end |
#typeexpr ⇒ Object
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.
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.
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_hash ⇒ Hash
Convert the object to a Hash suitable for JSON serialization.
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.
1159 1160 1161 |
# File 'lib/scjson/types.rb', line 1159 def to_json(*opts) JSON.generate(to_hash, *opts) end |