Class: Scjson::Types::ScriptProps
- Inherits:
-
Object
- Object
- Scjson::Types::ScriptProps
- Defined in:
- lib/scjson/types.rb
Overview
inline executable script.
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
-
#src ⇒ Object
Returns the value of attribute src.
Class Method Summary collapse
-
.from_hash(data) ⇒ ScriptProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ ScriptProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ ScriptProps
constructor
Instantiate a new ScriptProps 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) ⇒ ScriptProps
Instantiate a new ScriptProps object.
1568 1569 1570 1571 1572 |
# File 'lib/scjson/types.rb', line 1568 def initialize(**kwargs) @src = kwargs.fetch(:src, nil) @other_attributes = kwargs.fetch(:other_attributes, {}) @content = kwargs.fetch(:content, []) end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
1565 1566 1567 |
# File 'lib/scjson/types.rb', line 1565 def content @content end |
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
1565 1566 1567 |
# File 'lib/scjson/types.rb', line 1565 def other_attributes @other_attributes end |
#src ⇒ Object
Returns the value of attribute src.
1565 1566 1567 |
# File 'lib/scjson/types.rb', line 1565 def src @src end |
Class Method Details
.from_hash(data) ⇒ ScriptProps
Build an instance from a Hash representation.
1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 |
# File 'lib/scjson/types.rb', line 1577 def self.from_hash(data) raise ArgumentError, 'Expected Hash' unless data.is_a?(Hash) normalized = data.transform_keys(&:to_s) kwargs = {} kwargs[:src] = normalized.fetch('src', nil) kwargs[:other_attributes] = normalized.fetch('other_attributes', {}) kwargs[:content] = Array(normalized.fetch('content', [])) new(**kwargs) end |
.from_json(json) ⇒ ScriptProps
Deserialize an instance from a JSON payload.
1591 1592 1593 1594 |
# File 'lib/scjson/types.rb', line 1591 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.
1598 1599 1600 1601 1602 1603 1604 |
# File 'lib/scjson/types.rb', line 1598 def to_hash { 'src' => @src, 'other_attributes' => @other_attributes, 'content' => @content } end |
#to_json(*opts) ⇒ String
Serialize the object to JSON.
1609 1610 1611 |
# File 'lib/scjson/types.rb', line 1609 def to_json(*opts) JSON.generate(to_hash, *opts) end |