Class: Scjson::Types::ElseifProps
- Inherits:
-
Object
- Object
- Scjson::Types::ElseifProps
- Defined in:
- lib/scjson/types.rb
Overview
conditional branch following an ‘<if>`.
Instance Attribute Summary collapse
-
#cond ⇒ Object
Returns the value of attribute cond.
-
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
Class Method Summary collapse
-
.from_hash(data) ⇒ ElseifProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ ElseifProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ ElseifProps
constructor
Instantiate a new ElseifProps 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) ⇒ ElseifProps
Instantiate a new ElseifProps object.
620 621 622 623 |
# File 'lib/scjson/types.rb', line 620 def initialize(**kwargs) @cond = kwargs.fetch(:cond, '') @other_attributes = kwargs.fetch(:other_attributes, {}) end |
Instance Attribute Details
#cond ⇒ Object
Returns the value of attribute cond.
617 618 619 |
# File 'lib/scjson/types.rb', line 617 def cond @cond end |
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
617 618 619 |
# File 'lib/scjson/types.rb', line 617 def other_attributes @other_attributes end |
Class Method Details
.from_hash(data) ⇒ ElseifProps
Build an instance from a Hash representation.
628 629 630 631 632 633 634 635 636 |
# File 'lib/scjson/types.rb', line 628 def self.from_hash(data) raise ArgumentError, 'Expected Hash' unless data.is_a?(Hash) normalized = data.transform_keys(&:to_s) kwargs = {} kwargs[:cond] = normalized.fetch('cond', '') kwargs[:other_attributes] = normalized.fetch('other_attributes', {}) new(**kwargs) end |
.from_json(json) ⇒ ElseifProps
Deserialize an instance from a JSON payload.
641 642 643 644 |
# File 'lib/scjson/types.rb', line 641 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.
648 649 650 651 652 653 |
# File 'lib/scjson/types.rb', line 648 def to_hash { 'cond' => @cond, 'other_attributes' => @other_attributes } end |
#to_json(*opts) ⇒ String
Serialize the object to JSON.
658 659 660 |
# File 'lib/scjson/types.rb', line 658 def to_json(*opts) JSON.generate(to_hash, *opts) end |