Class: Scjson::Types::ParamProps
- Inherits:
-
Object
- Object
- Scjson::Types::ParamProps
- Defined in:
- lib/scjson/types.rb
Overview
parameter passed to ‘<invoke>` or `<send>`.
Instance Attribute Summary collapse
-
#expr ⇒ Object
Returns the value of attribute expr.
-
#location ⇒ Object
Returns the value of attribute location.
-
#name ⇒ Object
Returns the value of attribute name.
-
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
-
#other_element ⇒ Object
Returns the value of attribute other_element.
Class Method Summary collapse
-
.from_hash(data) ⇒ ParamProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ ParamProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ ParamProps
constructor
Instantiate a new ParamProps 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) ⇒ ParamProps
Instantiate a new ParamProps object.
1457 1458 1459 1460 1461 1462 1463 |
# File 'lib/scjson/types.rb', line 1457 def initialize(**kwargs) @other_element = kwargs.fetch(:other_element, []) @name = kwargs.fetch(:name, '') @expr = kwargs.fetch(:expr, nil) @location = kwargs.fetch(:location, nil) @other_attributes = kwargs.fetch(:other_attributes, {}) end |
Instance Attribute Details
#expr ⇒ Object
Returns the value of attribute expr.
1454 1455 1456 |
# File 'lib/scjson/types.rb', line 1454 def expr @expr end |
#location ⇒ Object
Returns the value of attribute location.
1454 1455 1456 |
# File 'lib/scjson/types.rb', line 1454 def location @location end |
#name ⇒ Object
Returns the value of attribute name.
1454 1455 1456 |
# File 'lib/scjson/types.rb', line 1454 def name @name end |
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
1454 1455 1456 |
# File 'lib/scjson/types.rb', line 1454 def other_attributes @other_attributes end |
#other_element ⇒ Object
Returns the value of attribute other_element.
1454 1455 1456 |
# File 'lib/scjson/types.rb', line 1454 def other_element @other_element end |
Class Method Details
.from_hash(data) ⇒ ParamProps
Build an instance from a Hash representation.
1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 |
# File 'lib/scjson/types.rb', line 1468 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[:name] = normalized.fetch('name', '') kwargs[:expr] = normalized.fetch('expr', nil) kwargs[:location] = normalized.fetch('location', nil) kwargs[:other_attributes] = normalized.fetch('other_attributes', {}) new(**kwargs) end |
.from_json(json) ⇒ ParamProps
Deserialize an instance from a JSON payload.
1484 1485 1486 1487 |
# File 'lib/scjson/types.rb', line 1484 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.
1491 1492 1493 1494 1495 1496 1497 1498 1499 |
# File 'lib/scjson/types.rb', line 1491 def to_hash { 'other_element' => @other_element, 'name' => @name, 'expr' => @expr, 'location' => @location, 'other_attributes' => @other_attributes } end |
#to_json(*opts) ⇒ String
Serialize the object to JSON.
1504 1505 1506 |
# File 'lib/scjson/types.rb', line 1504 def to_json(*opts) JSON.generate(to_hash, *opts) end |