Class: Scjson::Types::OnentryProps
- Inherits:
-
Object
- Object
- Scjson::Types::OnentryProps
- Defined in:
- lib/scjson/types.rb
Overview
Structured type for scjson elements.
Instance Attribute Summary collapse
-
#assign ⇒ Object
Returns the value of attribute assign.
-
#cancel ⇒ Object
Returns the value of attribute cancel.
-
#foreach ⇒ Object
Returns the value of attribute foreach.
-
#if_value ⇒ Object
Returns the value of attribute if_value.
-
#log ⇒ Object
Returns the value of attribute log.
-
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
-
#other_element ⇒ Object
Returns the value of attribute other_element.
-
#raise_value ⇒ Object
Returns the value of attribute raise_value.
-
#script ⇒ Object
Returns the value of attribute script.
-
#send ⇒ Object
Returns the value of attribute send.
Class Method Summary collapse
-
.from_hash(data) ⇒ OnentryProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ OnentryProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ OnentryProps
constructor
Instantiate a new OnentryProps 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) ⇒ OnentryProps
Instantiate a new OnentryProps object.
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 |
# File 'lib/scjson/types.rb', line 1229 def initialize(**kwargs) @other_element = kwargs.fetch(:other_element, []) @raise_value = kwargs.fetch(:raise_value, []) @if_value = kwargs.fetch(:if_value, []) @foreach = kwargs.fetch(:foreach, []) @send = kwargs.fetch(:send, []) @script = kwargs.fetch(:script, []) @assign = kwargs.fetch(:assign, []) @log = kwargs.fetch(:log, []) @cancel = kwargs.fetch(:cancel, []) @other_attributes = kwargs.fetch(:other_attributes, {}) end |
Instance Attribute Details
#assign ⇒ Object
Returns the value of attribute assign.
1226 1227 1228 |
# File 'lib/scjson/types.rb', line 1226 def assign @assign end |
#cancel ⇒ Object
Returns the value of attribute cancel.
1226 1227 1228 |
# File 'lib/scjson/types.rb', line 1226 def cancel @cancel end |
#foreach ⇒ Object
Returns the value of attribute foreach.
1226 1227 1228 |
# File 'lib/scjson/types.rb', line 1226 def foreach @foreach end |
#if_value ⇒ Object
Returns the value of attribute if_value.
1226 1227 1228 |
# File 'lib/scjson/types.rb', line 1226 def if_value @if_value end |
#log ⇒ Object
Returns the value of attribute log.
1226 1227 1228 |
# File 'lib/scjson/types.rb', line 1226 def log @log end |
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
1226 1227 1228 |
# File 'lib/scjson/types.rb', line 1226 def other_attributes @other_attributes end |
#other_element ⇒ Object
Returns the value of attribute other_element.
1226 1227 1228 |
# File 'lib/scjson/types.rb', line 1226 def other_element @other_element end |
#raise_value ⇒ Object
Returns the value of attribute raise_value.
1226 1227 1228 |
# File 'lib/scjson/types.rb', line 1226 def raise_value @raise_value end |
#script ⇒ Object
Returns the value of attribute script.
1226 1227 1228 |
# File 'lib/scjson/types.rb', line 1226 def script @script end |
#send ⇒ Object
Returns the value of attribute send.
1226 1227 1228 |
# File 'lib/scjson/types.rb', line 1226 def send @send end |
Class Method Details
.from_hash(data) ⇒ OnentryProps
Build an instance from a Hash representation.
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 |
# File 'lib/scjson/types.rb', line 1245 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[:raise_value] = Array(normalized.fetch('raise_value', [])).map { |item| RaiseProps.from_hash(item) } kwargs[:if_value] = Array(normalized.fetch('if_value', [])).map { |item| IfProps.from_hash(item) } kwargs[:foreach] = Array(normalized.fetch('foreach', [])).map { |item| ForeachProps.from_hash(item) } kwargs[:send] = Array(normalized.fetch('send', [])).map { |item| SendProps.from_hash(item) } kwargs[:script] = Array(normalized.fetch('script', [])).map { |item| ScriptProps.from_hash(item) } kwargs[:assign] = Array(normalized.fetch('assign', [])).map { |item| AssignProps.from_hash(item) } kwargs[:log] = Array(normalized.fetch('log', [])).map { |item| LogProps.from_hash(item) } kwargs[:cancel] = Array(normalized.fetch('cancel', [])).map { |item| CancelProps.from_hash(item) } kwargs[:other_attributes] = normalized.fetch('other_attributes', {}) new(**kwargs) end |
.from_json(json) ⇒ OnentryProps
Deserialize an instance from a JSON payload.
1266 1267 1268 1269 |
# File 'lib/scjson/types.rb', line 1266 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.
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 |
# File 'lib/scjson/types.rb', line 1273 def to_hash { 'other_element' => @other_element, 'raise_value' => (@raise_value || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'if_value' => (@if_value || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'foreach' => (@foreach || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'send' => (@send || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'script' => (@script || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'assign' => (@assign || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'log' => (@log || []).map { |item| item.respond_to?(:to_hash) ? item.to_hash : item }, 'cancel' => (@cancel || []).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.
1291 1292 1293 |
# File 'lib/scjson/types.rb', line 1291 def to_json(*opts) JSON.generate(to_hash, *opts) end |