Class: TXTextControl::ReportingCloud::TemplateInfo

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

Overview

Holds information about the merge blocks and merge fields in a template

in the template storage.

Author:

  • Thorsten Kummerow (@thomerow)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_name, merge_blocks, merge_fields) ⇒ TemplateInfo

Returns a new instance of TemplateInfo

Parameters:

  • template_name (String)

    The template file name.

  • merge_blocks (Array<MergeBlock>)

    The top level merge blocks in the template.

  • merge_fields (Array<MergeField>)

    The top level merge fields in the template.

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
44
45
# File 'lib/txtextcontrol/reportingcloud/template_info.rb', line 36

def initialize(template_name, merge_blocks, merge_fields)
  # Parameter validation
  raise ArgumentError, "Block name must be a string." if !template_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

  @template_name = template_name
  @merge_blocks = merge_blocks
  @merge_fields = merge_fields
end

Instance Attribute Details

#merge_blocksArray<MergeBlock> (readonly)

Contains all top level merge blocks in the template.

Returns:

  • (Array<MergeBlock>)

    the current value of merge_blocks



28
29
30
# File 'lib/txtextcontrol/reportingcloud/template_info.rb', line 28

def merge_blocks
  @merge_blocks
end

#merge_fieldsArray<MergeField> (readonly)

Contains all top level merge fields in the template.

Returns:

  • (Array<MergeField>)

    the current value of merge_fields



28
29
30
# File 'lib/txtextcontrol/reportingcloud/template_info.rb', line 28

def merge_fields
  @merge_fields
end

#template_nameString (readonly)

The template file name.

Returns:

  • (String)

    the current value of template_name



28
29
30
# File 'lib/txtextcontrol/reportingcloud/template_info.rb', line 28

def template_name
  @template_name
end

Class Method Details

.from_camelized_hash(hash) ⇒ TemplateInfo

Creates a TemplateInfo instance from a hash.

Parameters:

  • hash (Hash)

    The hash to try and create a TemplateInfo instance from.

Returns:

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/txtextcontrol/reportingcloud/template_info.rb', line 50

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

  name = hash["templateName"]
  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 TemplateInfo.new(name, blocks, fields)
end