Class: Scjson::Types::ElseProps

Inherits:
Object
  • Object
show all
Defined in:
lib/scjson/types.rb

Overview

fallback branch for ‘<if>` conditions.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ ElseProps

Instantiate a new ElseProps object.

Parameters:

  • kwargs (Hash)

    Optional keyword overrides.



575
576
577
# File 'lib/scjson/types.rb', line 575

def initialize(**kwargs)
  @other_attributes = kwargs.fetch(:other_attributes, {})
end

Instance Attribute Details

#other_attributesObject

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.

Parameters:

  • data (Hash)

    Canonical hash representation.

Returns:

Raises:

  • (ArgumentError)


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.

Parameters:

  • json (String)

    JSON document to decode.

Returns:



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_hashHash

Convert the object to a Hash suitable for JSON serialization.

Returns:

  • (Hash)


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.

Parameters:

  • opts (Array)

    JSON generation options.

Returns:

  • (String)


610
611
612
# File 'lib/scjson/types.rb', line 610

def to_json(*opts)
  JSON.generate(to_hash, *opts)
end