Class: DynamicPDFApi::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_client/Template.rb

Overview

Represents a document template.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Template

Initializes a new instance of the Template class.

Parameters:

  • id (String)

    The id string representing id for the template.



11
12
13
14
15
16
17
18
# File 'lib/ruby_client/Template.rb', line 11

def initialize(id)
  @id = if id.nil?
          SecureRandom.uuid
        else
          id
        end
  @elements = []
end

Instance Attribute Details

#elementsObject

Gets or sets the elements for the template.



28
29
30
# File 'lib/ruby_client/Template.rb', line 28

def elements
  @elements
end

#idObject

Gets or sets the id for the template.



23
24
25
# File 'lib/ruby_client/Template.rb', line 23

def id
  @id
end

Instance Method Details

#to_json(_options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ruby_client/Template.rb', line 30

def to_json(_options = {})
  elements = []
  @elements.each do |element|
    str = element unless element.nil?

    elements << str unless str.nil?
  end

  json_array = {}

  json_array['id'] = @id
  json_array['elements'] = @elements

  JSON.pretty_generate(json_array)
end