Class: Scjson::Types::DonedataProps
- Inherits:
-
Object
- Object
- Scjson::Types::DonedataProps
- Defined in:
- lib/scjson/types.rb
Overview
Structured type for scjson elements.
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
-
#param ⇒ Object
Returns the value of attribute param.
Class Method Summary collapse
-
.from_hash(data) ⇒ DonedataProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ DonedataProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ DonedataProps
constructor
Instantiate a new DonedataProps 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) ⇒ DonedataProps
Instantiate a new DonedataProps object.
521 522 523 524 525 |
# File 'lib/scjson/types.rb', line 521 def initialize(**kwargs) @content = kwargs.fetch(:content, nil) @param = kwargs.fetch(:param, []) @other_attributes = kwargs.fetch(:other_attributes, {}) end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
518 519 520 |
# File 'lib/scjson/types.rb', line 518 def content @content end |
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
518 519 520 |
# File 'lib/scjson/types.rb', line 518 def other_attributes @other_attributes end |
#param ⇒ Object
Returns the value of attribute param.
518 519 520 |
# File 'lib/scjson/types.rb', line 518 def param @param end |
Class Method Details
.from_hash(data) ⇒ DonedataProps
Build an instance from a Hash representation.
530 531 532 533 534 535 536 537 538 539 |
# File 'lib/scjson/types.rb', line 530 def self.from_hash(data) raise ArgumentError, 'Expected Hash' unless data.is_a?(Hash) normalized = data.transform_keys(&:to_s) kwargs = {} kwargs[:content] = normalized.key?('content') && normalized['content'] ? ContentProps.from_hash(normalized['content']) : nil kwargs[:param] = Array(normalized.fetch('param', [])).map { |item| ParamProps.from_hash(item) } kwargs[:other_attributes] = normalized.fetch('other_attributes', {}) new(**kwargs) end |
.from_json(json) ⇒ DonedataProps
Deserialize an instance from a JSON payload.
544 545 546 547 |
# File 'lib/scjson/types.rb', line 544 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.
551 552 553 554 555 556 557 |
# File 'lib/scjson/types.rb', line 551 def to_hash { 'content' => @content&.to_hash, 'param' => (@param || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'other_attributes' => @other_attributes } end |
#to_json(*opts) ⇒ String
Serialize the object to JSON.
562 563 564 |
# File 'lib/scjson/types.rb', line 562 def to_json(*opts) JSON.generate(to_hash, *opts) end |