Class: Scjson::Types::ScxmlProps
- Inherits:
-
Object
- Object
- Scjson::Types::ScxmlProps
- Defined in:
- lib/scjson/types.rb
Overview
Structured type for scjson elements.
Instance Attribute Summary collapse
-
#binding ⇒ Object
Returns the value of attribute binding.
-
#datamodel ⇒ Object
Returns the value of attribute datamodel.
-
#datamodel_attribute ⇒ Object
Returns the value of attribute datamodel_attribute.
-
#exmode ⇒ Object
Returns the value of attribute exmode.
-
#final ⇒ Object
Returns the value of attribute final.
-
#initial ⇒ Object
Returns the value of attribute initial.
-
#name ⇒ Object
Returns the value of attribute name.
-
#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.
-
#script ⇒ Object
Returns the value of attribute script.
-
#state ⇒ Object
Returns the value of attribute state.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.from_hash(data) ⇒ ScxmlProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ ScxmlProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ ScxmlProps
constructor
Instantiate a new ScxmlProps 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) ⇒ ScxmlProps
Instantiate a new ScxmlProps object.
1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 |
# File 'lib/scjson/types.rb', line 1622 def initialize(**kwargs) @state = kwargs.fetch(:state, []) @parallel = kwargs.fetch(:parallel, []) @final = kwargs.fetch(:final, []) @datamodel = kwargs.fetch(:datamodel, []) @script = kwargs.fetch(:script, []) @other_element = kwargs.fetch(:other_element, []) @initial = kwargs.fetch(:initial, []) @name = kwargs.fetch(:name, nil) @version = kwargs.fetch(:version, '1.0') @datamodel_attribute = kwargs.fetch(:datamodel_attribute, 'null') @binding = kwargs.fetch(:binding, nil) @exmode = kwargs.fetch(:exmode, nil) @other_attributes = kwargs.fetch(:other_attributes, {}) end |
Instance Attribute Details
#binding ⇒ Object
Returns the value of attribute binding.
1619 1620 1621 |
# File 'lib/scjson/types.rb', line 1619 def binding @binding end |
#datamodel ⇒ Object
Returns the value of attribute datamodel.
1619 1620 1621 |
# File 'lib/scjson/types.rb', line 1619 def datamodel @datamodel end |
#datamodel_attribute ⇒ Object
Returns the value of attribute datamodel_attribute.
1619 1620 1621 |
# File 'lib/scjson/types.rb', line 1619 def datamodel_attribute @datamodel_attribute end |
#exmode ⇒ Object
Returns the value of attribute exmode.
1619 1620 1621 |
# File 'lib/scjson/types.rb', line 1619 def exmode @exmode end |
#final ⇒ Object
Returns the value of attribute final.
1619 1620 1621 |
# File 'lib/scjson/types.rb', line 1619 def final @final end |
#initial ⇒ Object
Returns the value of attribute initial.
1619 1620 1621 |
# File 'lib/scjson/types.rb', line 1619 def initial @initial end |
#name ⇒ Object
Returns the value of attribute name.
1619 1620 1621 |
# File 'lib/scjson/types.rb', line 1619 def name @name end |
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
1619 1620 1621 |
# File 'lib/scjson/types.rb', line 1619 def other_attributes @other_attributes end |
#other_element ⇒ Object
Returns the value of attribute other_element.
1619 1620 1621 |
# File 'lib/scjson/types.rb', line 1619 def other_element @other_element end |
#parallel ⇒ Object
Returns the value of attribute parallel.
1619 1620 1621 |
# File 'lib/scjson/types.rb', line 1619 def parallel @parallel end |
#script ⇒ Object
Returns the value of attribute script.
1619 1620 1621 |
# File 'lib/scjson/types.rb', line 1619 def script @script end |
#state ⇒ Object
Returns the value of attribute state.
1619 1620 1621 |
# File 'lib/scjson/types.rb', line 1619 def state @state end |
#version ⇒ Object
Returns the value of attribute version.
1619 1620 1621 |
# File 'lib/scjson/types.rb', line 1619 def version @version end |
Class Method Details
.from_hash(data) ⇒ ScxmlProps
Build an instance from a Hash representation.
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 |
# File 'lib/scjson/types.rb', line 1641 def self.from_hash(data) raise ArgumentError, 'Expected Hash' unless data.is_a?(Hash) normalized = data.transform_keys(&:to_s) kwargs = {} 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[:final] = Array(normalized.fetch('final', [])).map { |item| FinalProps.from_hash(item) } kwargs[:datamodel] = Array(normalized.fetch('datamodel', [])).map { |item| DatamodelProps.from_hash(item) } kwargs[:script] = Array(normalized.fetch('script', [])).map { |item| ScriptProps.from_hash(item) } kwargs[:other_element] = Array(normalized.fetch('other_element', [])) kwargs[:initial] = Array(normalized.fetch('initial', [])) kwargs[:name] = normalized.fetch('name', nil) kwargs[:version] = normalized.fetch('version', nil) kwargs[:datamodel_attribute] = normalized.fetch('datamodel_attribute', 'null') kwargs[:binding] = normalized.key?('binding') ? BindingDatatypeProps.coerce(normalized['binding'], allow_nil: true) : nil kwargs[:exmode] = normalized.key?('exmode') ? ExmodeDatatypeProps.coerce(normalized['exmode'], allow_nil: true) : nil kwargs[:other_attributes] = normalized.fetch('other_attributes', {}) new(**kwargs) end |
.from_json(json) ⇒ ScxmlProps
Deserialize an instance from a JSON payload.
1665 1666 1667 1668 |
# File 'lib/scjson/types.rb', line 1665 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.
1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 |
# File 'lib/scjson/types.rb', line 1672 def to_hash { '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 }, 'final' => (@final || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'datamodel' => (@datamodel || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'script' => (@script || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'other_element' => @other_element, 'initial' => @initial, 'name' => @name, 'version' => @version, 'datamodel_attribute' => @datamodel_attribute, 'binding' => @binding, 'exmode' => @exmode, 'other_attributes' => @other_attributes } end |
#to_json(*opts) ⇒ String
Serialize the object to JSON.
1693 1694 1695 |
# File 'lib/scjson/types.rb', line 1693 def to_json(*opts) JSON.generate(to_hash, *opts) end |