Class: Scjson::Types::InitialProps
- Inherits:
-
Object
- Object
- Scjson::Types::InitialProps
- Defined in:
- lib/scjson/types.rb
Overview
Structured type for scjson elements.
Instance Attribute Summary collapse
-
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
-
#other_element ⇒ Object
Returns the value of attribute other_element.
-
#transition ⇒ Object
Returns the value of attribute transition.
Class Method Summary collapse
-
.from_hash(data) ⇒ InitialProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ InitialProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ InitialProps
constructor
Instantiate a new InitialProps 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) ⇒ InitialProps
Instantiate a new InitialProps object.
1034 1035 1036 1037 1038 |
# File 'lib/scjson/types.rb', line 1034 def initialize(**kwargs) @other_element = kwargs.fetch(:other_element, []) @transition = kwargs.fetch(:transition, TransitionProps.new) @other_attributes = kwargs.fetch(:other_attributes, {}) end |
Instance Attribute Details
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
1031 1032 1033 |
# File 'lib/scjson/types.rb', line 1031 def other_attributes @other_attributes end |
#other_element ⇒ Object
Returns the value of attribute other_element.
1031 1032 1033 |
# File 'lib/scjson/types.rb', line 1031 def other_element @other_element end |
#transition ⇒ Object
Returns the value of attribute transition.
1031 1032 1033 |
# File 'lib/scjson/types.rb', line 1031 def transition @transition end |
Class Method Details
.from_hash(data) ⇒ InitialProps
Build an instance from a Hash representation.
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 |
# File 'lib/scjson/types.rb', line 1043 def self.from_hash(data) raise ArgumentError, 'Expected Hash' unless data.is_a?(Hash) normalized = data.transform_keys(&:to_s) kwargs = {} kwargs[:other_element] = Array(normalized.fetch('other_element', [])) kwargs[:transition] = normalized.key?('transition') && normalized['transition'] ? TransitionProps.from_hash(normalized['transition']) : TransitionProps.new kwargs[:other_attributes] = normalized.fetch('other_attributes', {}) new(**kwargs) end |
.from_json(json) ⇒ InitialProps
Deserialize an instance from a JSON payload.
1057 1058 1059 1060 |
# File 'lib/scjson/types.rb', line 1057 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.
1064 1065 1066 1067 1068 1069 1070 |
# File 'lib/scjson/types.rb', line 1064 def to_hash { 'other_element' => @other_element, 'transition' => @transition&.to_hash, 'other_attributes' => @other_attributes } end |
#to_json(*opts) ⇒ String
Serialize the object to JSON.
1075 1076 1077 |
# File 'lib/scjson/types.rb', line 1075 def to_json(*opts) JSON.generate(to_hash, *opts) end |