Class: Scjson::Types::AssignProps
- Inherits:
-
Object
- Object
- Scjson::Types::AssignProps
- Defined in:
- lib/scjson/types.rb
Overview
update a datamodel location with an expression or value.
Instance Attribute Summary collapse
-
#attr ⇒ Object
Returns the value of attribute attr.
-
#content ⇒ Object
Returns the value of attribute content.
-
#expr ⇒ Object
Returns the value of attribute expr.
-
#location ⇒ Object
Returns the value of attribute location.
-
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
-
#type_value ⇒ Object
Returns the value of attribute type_value.
Class Method Summary collapse
-
.from_hash(data) ⇒ AssignProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ AssignProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ AssignProps
constructor
Instantiate a new AssignProps 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) ⇒ AssignProps
Instantiate a new AssignProps object.
230 231 232 233 234 235 236 237 |
# File 'lib/scjson/types.rb', line 230 def initialize(**kwargs) @location = kwargs.fetch(:location, '') @expr = kwargs.fetch(:expr, nil) @type_value = kwargs.fetch(:type_value, AssignTypeDatatypeProps::REPLACECHILDREN) @attr = kwargs.fetch(:attr, nil) @other_attributes = kwargs.fetch(:other_attributes, {}) @content = kwargs.fetch(:content, []) end |
Instance Attribute Details
#attr ⇒ Object
Returns the value of attribute attr.
227 228 229 |
# File 'lib/scjson/types.rb', line 227 def attr @attr end |
#content ⇒ Object
Returns the value of attribute content.
227 228 229 |
# File 'lib/scjson/types.rb', line 227 def content @content end |
#expr ⇒ Object
Returns the value of attribute expr.
227 228 229 |
# File 'lib/scjson/types.rb', line 227 def expr @expr end |
#location ⇒ Object
Returns the value of attribute location.
227 228 229 |
# File 'lib/scjson/types.rb', line 227 def location @location end |
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
227 228 229 |
# File 'lib/scjson/types.rb', line 227 def other_attributes @other_attributes end |
#type_value ⇒ Object
Returns the value of attribute type_value.
227 228 229 |
# File 'lib/scjson/types.rb', line 227 def type_value @type_value end |
Class Method Details
.from_hash(data) ⇒ AssignProps
Build an instance from a Hash representation.
242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/scjson/types.rb', line 242 def self.from_hash(data) raise ArgumentError, 'Expected Hash' unless data.is_a?(Hash) normalized = data.transform_keys(&:to_s) kwargs = {} kwargs[:location] = normalized.fetch('location', '') kwargs[:expr] = normalized.fetch('expr', nil) kwargs[:type_value] = AssignTypeDatatypeProps.coerce(normalized.fetch('type_value', AssignTypeDatatypeProps::REPLACECHILDREN)) kwargs[:attr] = normalized.fetch('attr', nil) kwargs[:other_attributes] = normalized.fetch('other_attributes', {}) kwargs[:content] = Array(normalized.fetch('content', [])) new(**kwargs) end |
.from_json(json) ⇒ AssignProps
Deserialize an instance from a JSON payload.
259 260 261 262 |
# File 'lib/scjson/types.rb', line 259 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.
266 267 268 269 270 271 272 273 274 275 |
# File 'lib/scjson/types.rb', line 266 def to_hash { 'location' => @location, 'expr' => @expr, 'type_value' => @type_value, 'attr' => @attr, 'other_attributes' => @other_attributes, 'content' => @content } end |
#to_json(*opts) ⇒ String
Serialize the object to JSON.
280 281 282 |
# File 'lib/scjson/types.rb', line 280 def to_json(*opts) JSON.generate(to_hash, *opts) end |