Class: Scjson::Types::SendProps
- Inherits:
-
Object
- Object
- Scjson::Types::SendProps
- Defined in:
- lib/scjson/types.rb
Overview
Structured type for scjson elements.
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#delay ⇒ Object
Returns the value of attribute delay.
-
#delayexpr ⇒ Object
Returns the value of attribute delayexpr.
-
#event ⇒ Object
Returns the value of attribute event.
-
#eventexpr ⇒ Object
Returns the value of attribute eventexpr.
-
#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.
-
#target ⇒ Object
Returns the value of attribute target.
-
#targetexpr ⇒ Object
Returns the value of attribute targetexpr.
-
#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) ⇒ SendProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ SendProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ SendProps
constructor
Instantiate a new SendProps 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) ⇒ SendProps
Instantiate a new SendProps object.
1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 |
# File 'lib/scjson/types.rb', line 1703 def initialize(**kwargs) @content = kwargs.fetch(:content, []) @param = kwargs.fetch(:param, []) @other_element = kwargs.fetch(:other_element, []) @event = kwargs.fetch(:event, nil) @eventexpr = kwargs.fetch(:eventexpr, nil) @target = kwargs.fetch(:target, nil) @targetexpr = kwargs.fetch(:targetexpr, nil) @type_value = kwargs.fetch(:type_value, 'scxml') @typeexpr = kwargs.fetch(:typeexpr, nil) @id = kwargs.fetch(:id, nil) @idlocation = kwargs.fetch(:idlocation, nil) @delay = kwargs.fetch(:delay, '0s') @delayexpr = kwargs.fetch(:delayexpr, nil) @namelist = kwargs.fetch(:namelist, nil) @other_attributes = kwargs.fetch(:other_attributes, {}) end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def content @content end |
#delay ⇒ Object
Returns the value of attribute delay.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def delay @delay end |
#delayexpr ⇒ Object
Returns the value of attribute delayexpr.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def delayexpr @delayexpr end |
#event ⇒ Object
Returns the value of attribute event.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def event @event end |
#eventexpr ⇒ Object
Returns the value of attribute eventexpr.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def eventexpr @eventexpr end |
#id ⇒ Object
Returns the value of attribute id.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def id @id end |
#idlocation ⇒ Object
Returns the value of attribute idlocation.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def idlocation @idlocation end |
#namelist ⇒ Object
Returns the value of attribute namelist.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def namelist @namelist end |
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def other_attributes @other_attributes end |
#other_element ⇒ Object
Returns the value of attribute other_element.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def other_element @other_element end |
#param ⇒ Object
Returns the value of attribute param.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def param @param end |
#target ⇒ Object
Returns the value of attribute target.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def target @target end |
#targetexpr ⇒ Object
Returns the value of attribute targetexpr.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def targetexpr @targetexpr end |
#type_value ⇒ Object
Returns the value of attribute type_value.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def type_value @type_value end |
#typeexpr ⇒ Object
Returns the value of attribute typeexpr.
1700 1701 1702 |
# File 'lib/scjson/types.rb', line 1700 def typeexpr @typeexpr end |
Class Method Details
.from_hash(data) ⇒ SendProps
Build an instance from a Hash representation.
1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 |
# File 'lib/scjson/types.rb', line 1724 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[:other_element] = Array(normalized.fetch('other_element', [])) kwargs[:event] = normalized.fetch('event', nil) kwargs[:eventexpr] = normalized.fetch('eventexpr', nil) kwargs[:target] = normalized.fetch('target', nil) kwargs[:targetexpr] = normalized.fetch('targetexpr', nil) kwargs[:type_value] = normalized.fetch('type_value', 'scxml') kwargs[:typeexpr] = normalized.fetch('typeexpr', nil) kwargs[:id] = normalized.fetch('id', nil) kwargs[:idlocation] = normalized.fetch('idlocation', nil) kwargs[:delay] = normalized.fetch('delay', '0s') kwargs[:delayexpr] = normalized.fetch('delayexpr', nil) kwargs[:namelist] = normalized.fetch('namelist', nil) kwargs[:other_attributes] = normalized.fetch('other_attributes', {}) new(**kwargs) end |
.from_json(json) ⇒ SendProps
Deserialize an instance from a JSON payload.
1750 1751 1752 1753 |
# File 'lib/scjson/types.rb', line 1750 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.
1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 |
# File 'lib/scjson/types.rb', line 1757 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 }, 'other_element' => @other_element, 'event' => @event, 'eventexpr' => @eventexpr, 'target' => @target, 'targetexpr' => @targetexpr, 'type_value' => @type_value, 'typeexpr' => @typeexpr, 'id' => @id, 'idlocation' => @idlocation, 'delay' => @delay, 'delayexpr' => @delayexpr, 'namelist' => @namelist, 'other_attributes' => @other_attributes } end |
#to_json(*opts) ⇒ String
Serialize the object to JSON.
1780 1781 1782 |
# File 'lib/scjson/types.rb', line 1780 def to_json(*opts) JSON.generate(to_hash, *opts) end |