Class: Courier::Send::ElementalGroupNode

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/send/types/elemental_group_node.rb

Overview

Allows you to group elements together. This can be useful when used in combination with “if” or “loop”. See [control flow docs](www.courier.com/docs/platform/content/elemental/control-flow/) for more details.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elements:, channels: nil, ref: nil, if_: nil, loop: nil, additional_properties: nil) ⇒ Send::ElementalGroupNode

Parameters:

  • elements (Array<Send::ElementalNode>)

    Sub elements to render.

  • channels (Array<String>) (defaults to: nil)
  • ref (String) (defaults to: nil)
  • if_ (String) (defaults to: nil)
  • loop (String) (defaults to: nil)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/trycourier/send/types/elemental_group_node.rb', line 19

def initialize(elements:, channels: nil, ref: nil, if_: nil, loop: nil, additional_properties: nil)
  # @type [Array<Send::ElementalNode>] Sub elements to render.
  @elements = elements
  # @type [Array<String>]
  @channels = channels
  # @type [String]
  @ref = ref
  # @type [String]
  @if_ = if_
  # @type [String]
  @loop = loop
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



10
11
12
# File 'lib/trycourier/send/types/elemental_group_node.rb', line 10

def additional_properties
  @additional_properties
end

#channelsObject (readonly)

Returns the value of attribute channels.



10
11
12
# File 'lib/trycourier/send/types/elemental_group_node.rb', line 10

def channels
  @channels
end

#elementsObject (readonly)

Returns the value of attribute elements.



10
11
12
# File 'lib/trycourier/send/types/elemental_group_node.rb', line 10

def elements
  @elements
end

#if_Object (readonly)

Returns the value of attribute if_.



10
11
12
# File 'lib/trycourier/send/types/elemental_group_node.rb', line 10

def if_
  @if_
end

#loopObject (readonly)

Returns the value of attribute loop.



10
11
12
# File 'lib/trycourier/send/types/elemental_group_node.rb', line 10

def loop
  @loop
end

#refObject (readonly)

Returns the value of attribute ref.



10
11
12
# File 'lib/trycourier/send/types/elemental_group_node.rb', line 10

def ref
  @ref
end

Class Method Details

.from_json(json_object:) ⇒ Send::ElementalGroupNode

Deserialize a JSON object to an instance of ElementalGroupNode

Parameters:

  • json_object (JSON)

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/trycourier/send/types/elemental_group_node.rb', line 38

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  elements = parsed_json["elements"]&.map do |v|
    v = v.to_json
    Send::ElementalNode.from_json(json_object: v)
  end
  channels = struct.channels
  ref = struct.ref
  if_ = struct.if
  loop = struct.loop
  new(elements: elements, channels: channels, ref: ref, if_: if_, loop: loop, additional_properties: struct)
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


63
64
65
66
67
68
69
# File 'lib/trycourier/send/types/elemental_group_node.rb', line 63

def self.validate_raw(obj:)
  obj.elements.is_a?(Array) != false || raise("Passed value for field obj.elements is not the expected type, validation failed.")
  obj.channels&.is_a?(Array) != false || raise("Passed value for field obj.channels is not the expected type, validation failed.")
  obj.ref&.is_a?(String) != false || raise("Passed value for field obj.ref is not the expected type, validation failed.")
  obj.if_&.is_a?(String) != false || raise("Passed value for field obj.if_ is not the expected type, validation failed.")
  obj.loop&.is_a?(String) != false || raise("Passed value for field obj.loop is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of ElementalGroupNode to a JSON object

Returns:

  • (JSON)


55
56
57
# File 'lib/trycourier/send/types/elemental_group_node.rb', line 55

def to_json(*_args)
  { "elements": @elements, "channels": @channels, "ref": @ref, "if": @if_, "loop": @loop }.to_json
end