Class: Scjson::Types::ForeachProps
- Inherits:
-
Object
- Object
- Scjson::Types::ForeachProps
- Defined in:
- lib/scjson/types.rb
Overview
Structured type for scjson elements.
Instance Attribute Summary collapse
-
#array ⇒ Object
Returns the value of attribute array.
-
#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.
-
#index ⇒ Object
Returns the value of attribute index.
-
#item ⇒ Object
Returns the value of attribute item.
-
#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) ⇒ ForeachProps
Build an instance from a Hash representation.
-
.from_json(json) ⇒ ForeachProps
Deserialize an instance from a JSON payload.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ ForeachProps
constructor
Instantiate a new ForeachProps 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) ⇒ ForeachProps
Instantiate a new ForeachProps object.
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 |
# File 'lib/scjson/types.rb', line 806 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, []) @array = kwargs.fetch(:array, '') @item = kwargs.fetch(:item, '') @index = kwargs.fetch(:index, nil) @other_attributes = kwargs.fetch(:other_attributes, {}) end |
Instance Attribute Details
#array ⇒ Object
Returns the value of attribute array.
803 804 805 |
# File 'lib/scjson/types.rb', line 803 def array @array end |
#assign ⇒ Object
Returns the value of attribute assign.
803 804 805 |
# File 'lib/scjson/types.rb', line 803 def assign @assign end |
#cancel ⇒ Object
Returns the value of attribute cancel.
803 804 805 |
# File 'lib/scjson/types.rb', line 803 def cancel @cancel end |
#foreach ⇒ Object
Returns the value of attribute foreach.
803 804 805 |
# File 'lib/scjson/types.rb', line 803 def foreach @foreach end |
#if_value ⇒ Object
Returns the value of attribute if_value.
803 804 805 |
# File 'lib/scjson/types.rb', line 803 def if_value @if_value end |
#index ⇒ Object
Returns the value of attribute index.
803 804 805 |
# File 'lib/scjson/types.rb', line 803 def index @index end |
#item ⇒ Object
Returns the value of attribute item.
803 804 805 |
# File 'lib/scjson/types.rb', line 803 def item @item end |
#log ⇒ Object
Returns the value of attribute log.
803 804 805 |
# File 'lib/scjson/types.rb', line 803 def log @log end |
#other_attributes ⇒ Object
Returns the value of attribute other_attributes.
803 804 805 |
# File 'lib/scjson/types.rb', line 803 def other_attributes @other_attributes end |
#other_element ⇒ Object
Returns the value of attribute other_element.
803 804 805 |
# File 'lib/scjson/types.rb', line 803 def other_element @other_element end |
#raise_value ⇒ Object
Returns the value of attribute raise_value.
803 804 805 |
# File 'lib/scjson/types.rb', line 803 def raise_value @raise_value end |
#script ⇒ Object
Returns the value of attribute script.
803 804 805 |
# File 'lib/scjson/types.rb', line 803 def script @script end |
#send ⇒ Object
Returns the value of attribute send.
803 804 805 |
# File 'lib/scjson/types.rb', line 803 def send @send end |
Class Method Details
.from_hash(data) ⇒ ForeachProps
Build an instance from a Hash representation.
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 |
# File 'lib/scjson/types.rb', line 825 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[:array] = normalized.fetch('array', '') kwargs[:item] = normalized.fetch('item', '') kwargs[:index] = normalized.fetch('index', nil) kwargs[:other_attributes] = normalized.fetch('other_attributes', {}) new(**kwargs) end |
.from_json(json) ⇒ ForeachProps
Deserialize an instance from a JSON payload.
849 850 851 852 |
# File 'lib/scjson/types.rb', line 849 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.
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
# File 'lib/scjson/types.rb', line 856 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 }, 'array' => @array, 'item' => @item, 'index' => @index, 'other_attributes' => @other_attributes } end |
#to_json(*opts) ⇒ String
Serialize the object to JSON.
877 878 879 |
# File 'lib/scjson/types.rb', line 877 def to_json(*opts) JSON.generate(to_hash, *opts) end |