Class: Scjson::Types::ParallelProps
- Inherits:
-
Object
- Object
- Scjson::Types::ParallelProps
- Defined in:
- lib/scjson/types.rb
Overview
Structured type for scjson elements.
Instance Attribute Summary collapse
-
#datamodel ⇒ Object
Returns the value of attribute datamodel.
-
#history ⇒ Object
Returns the value of attribute history.
-
#id ⇒ Object
Returns the value of attribute id.
-
#invoke ⇒ Object
Returns the value of attribute invoke.
-
#onentry ⇒ Object
Returns the value of attribute onentry.
-
#onexit ⇒ Object
Returns the value of attribute onexit.
-
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
-
#other_element ⇒ Object
Returns the value of attribute other_element.
-
#parallel ⇒ Object
Returns the value of attribute parallel.
-
#state ⇒ Object
Returns the value of attribute state.
-
#transition ⇒ Object
Returns the value of attribute transition.
Class Method Summary collapse
-
.from_hash(data) ⇒ ParallelProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ ParallelProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ ParallelProps
constructor
Instantiate a new ParallelProps 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) ⇒ ParallelProps
Instantiate a new ParallelProps object.
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 |
# File 'lib/scjson/types.rb', line 1379 def initialize(**kwargs) @onentry = kwargs.fetch(:onentry, []) @onexit = kwargs.fetch(:onexit, []) @transition = kwargs.fetch(:transition, []) @state = kwargs.fetch(:state, []) @parallel = kwargs.fetch(:parallel, []) @history = kwargs.fetch(:history, []) @datamodel = kwargs.fetch(:datamodel, []) @invoke = kwargs.fetch(:invoke, []) @other_element = kwargs.fetch(:other_element, []) @id = kwargs.fetch(:id, nil) @other_attributes = kwargs.fetch(:other_attributes, {}) end |
Instance Attribute Details
#datamodel ⇒ Object
Returns the value of attribute datamodel.
1376 1377 1378 |
# File 'lib/scjson/types.rb', line 1376 def datamodel @datamodel end |
#history ⇒ Object
Returns the value of attribute history.
1376 1377 1378 |
# File 'lib/scjson/types.rb', line 1376 def history @history end |
#id ⇒ Object
Returns the value of attribute id.
1376 1377 1378 |
# File 'lib/scjson/types.rb', line 1376 def id @id end |
#invoke ⇒ Object
Returns the value of attribute invoke.
1376 1377 1378 |
# File 'lib/scjson/types.rb', line 1376 def invoke @invoke end |
#onentry ⇒ Object
Returns the value of attribute onentry.
1376 1377 1378 |
# File 'lib/scjson/types.rb', line 1376 def onentry @onentry end |
#onexit ⇒ Object
Returns the value of attribute onexit.
1376 1377 1378 |
# File 'lib/scjson/types.rb', line 1376 def onexit @onexit end |
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
1376 1377 1378 |
# File 'lib/scjson/types.rb', line 1376 def other_attributes @other_attributes end |
#other_element ⇒ Object
Returns the value of attribute other_element.
1376 1377 1378 |
# File 'lib/scjson/types.rb', line 1376 def other_element @other_element end |
#parallel ⇒ Object
Returns the value of attribute parallel.
1376 1377 1378 |
# File 'lib/scjson/types.rb', line 1376 def parallel @parallel end |
#state ⇒ Object
Returns the value of attribute state.
1376 1377 1378 |
# File 'lib/scjson/types.rb', line 1376 def state @state end |
#transition ⇒ Object
Returns the value of attribute transition.
1376 1377 1378 |
# File 'lib/scjson/types.rb', line 1376 def transition @transition end |
Class Method Details
.from_hash(data) ⇒ ParallelProps
Build an instance from a Hash representation.
1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 |
# File 'lib/scjson/types.rb', line 1396 def self.from_hash(data) raise ArgumentError, 'Expected Hash' unless data.is_a?(Hash) normalized = data.transform_keys(&:to_s) kwargs = {} kwargs[:onentry] = Array(normalized.fetch('onentry', [])).map { |item| OnentryProps.from_hash(item) } kwargs[:onexit] = Array(normalized.fetch('onexit', [])).map { |item| OnexitProps.from_hash(item) } kwargs[:transition] = Array(normalized.fetch('transition', [])).map { |item| TransitionProps.from_hash(item) } kwargs[:state] = Array(normalized.fetch('state', [])).map { |item| StateProps.from_hash(item) } kwargs[:parallel] = Array(normalized.fetch('parallel', [])).map { |item| ParallelProps.from_hash(item) } kwargs[:history] = Array(normalized.fetch('history', [])).map { |item| HistoryProps.from_hash(item) } kwargs[:datamodel] = Array(normalized.fetch('datamodel', [])).map { |item| DatamodelProps.from_hash(item) } kwargs[:invoke] = Array(normalized.fetch('invoke', [])).map { |item| InvokeProps.from_hash(item) } kwargs[:other_element] = Array(normalized.fetch('other_element', [])) kwargs[:id] = normalized.fetch('id', nil) kwargs[:other_attributes] = normalized.fetch('other_attributes', {}) new(**kwargs) end |
.from_json(json) ⇒ ParallelProps
Deserialize an instance from a JSON payload.
1418 1419 1420 1421 |
# File 'lib/scjson/types.rb', line 1418 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.
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 |
# File 'lib/scjson/types.rb', line 1425 def to_hash { 'onentry' => (@onentry || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'onexit' => (@onexit || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'transition' => (@transition || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'state' => (@state || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'parallel' => (@parallel || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'history' => (@history || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'datamodel' => (@datamodel || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'invoke' => (@invoke || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'other_element' => @other_element, 'id' => @id, 'other_attributes' => @other_attributes } end |
#to_json(*opts) ⇒ String
Serialize the object to JSON.
1444 1445 1446 |
# File 'lib/scjson/types.rb', line 1444 def to_json(*opts) JSON.generate(to_hash, *opts) end |