Class: Scjson::Types::ElseProps
- Inherits:
-
Object
- Object
- Scjson::Types::ElseProps
- Defined in:
- lib/scjson/types.rb
Overview
fallback branch for ‘<if>` conditions.
Instance Attribute Summary collapse
-
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
Class Method Summary collapse
-
.from_hash(data) ⇒ ElseProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ ElseProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ ElseProps
constructor
Instantiate a new ElseProps 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) ⇒ ElseProps
Instantiate a new ElseProps object.
575 576 577 |
# File 'lib/scjson/types.rb', line 575 def initialize(**kwargs) @other_attributes = kwargs.fetch(:other_attributes, {}) end |
Instance Attribute Details
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
572 573 574 |
# File 'lib/scjson/types.rb', line 572 def other_attributes @other_attributes end |
Class Method Details
.from_hash(data) ⇒ ElseProps
Build an instance from a Hash representation.
582 583 584 585 586 587 588 589 |
# File 'lib/scjson/types.rb', line 582 def self.from_hash(data) raise ArgumentError, 'Expected Hash' unless data.is_a?(Hash) normalized = data.transform_keys(&:to_s) kwargs = {} kwargs[:other_attributes] = normalized.fetch('other_attributes', {}) new(**kwargs) end |
.from_json(json) ⇒ ElseProps
Deserialize an instance from a JSON payload.
594 595 596 597 |
# File 'lib/scjson/types.rb', line 594 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.
601 602 603 604 605 |
# File 'lib/scjson/types.rb', line 601 def to_hash { 'other_attributes' => @other_attributes } end |
#to_json(*opts) ⇒ String
Serialize the object to JSON.
610 611 612 |
# File 'lib/scjson/types.rb', line 610 def to_json(*opts) JSON.generate(to_hash, *opts) end |