Class: TXTextControl::ReportingCloud::MergeBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/txtextcontrol/reportingcloud/merge_block.rb

Overview

Represents a merge block in a document template.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, merge_blocks, merge_fields) ⇒ MergeBlock

Returns a new instance of MergeBlock

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
# File 'lib/txtextcontrol/reportingcloud/merge_block.rb', line 30

def initialize(name, merge_blocks, merge_fields)
  # Parameter validation
  raise ArgumentError, "Block name must be a string." if !name.kind_of? String
  raise ArgumentError, "Parameter merge_blocks must be an array." if !merge_blocks.kind_of? Array
  raise ArgumentError, "Parameter merge_fields must be an array." if !merge_fields.kind_of? Array

  @name = name
  @merge_blocks = merge_blocks
  @merge_fields = merge_fields
end

Instance Attribute Details

#merge_blocksArray<MergeBlock> (readonly)

The merge blocks nested inside the merge block.

Returns:

  • (Array<MergeBlock>)

    the current value of merge_blocks



25
26
27
# File 'lib/txtextcontrol/reportingcloud/merge_block.rb', line 25

def merge_blocks
  @merge_blocks
end

#merge_fieldsArray<MergeField> (readonly)

The merge fields inside the merge block.

Returns:

  • (Array<MergeField>)

    the current value of merge_fields



25
26
27
# File 'lib/txtextcontrol/reportingcloud/merge_block.rb', line 25

def merge_fields
  @merge_fields
end

#nameString (readonly)

The merge block's' name.

Returns:

  • (String)

    the current value of name



25
26
27
# File 'lib/txtextcontrol/reportingcloud/merge_block.rb', line 25

def name
  @name
end

Class Method Details

.from_camelized_hash(hash) ⇒ MergeBlock

Creates an MergeBlock instance from a hash.

Parameters:

  • hash (Hash)

    The hash to try and create an MergeBlock instance from.

Returns:

  • (MergeBlock)

    A newly created MergeBlock instance.

Raises:

  • (ArgumentError)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/txtextcontrol/reportingcloud/merge_block.rb', line 44

def self.from_camelized_hash(hash) 
  # Parameter validation
  raise ArgumentError, "Parameter must be a Hash." if !hash.kind_of? Hash

  name = hash["name"]
  blocks = Array.new
  hash["mergeBlocks"].each do |elem|
    blocks.push(MergeBlock.from_camelized_hash(elem))
  end
  fields = Array.new 
  hash["mergeFields"].each do |elem|
    fields.push(MergeField.from_camelized_hash(elem))
  end
  return MergeBlock.new(name, blocks, fields)
end