Class: DynamicPDFApi::ImageElement

Inherits:
Element
  • Object
show all
Defined in:
lib/ruby_client/Elements/ImageElement.rb

Overview

Represents an image element.

This class can be used to place images on a page.

Instance Attribute Summary collapse

Attributes inherited from Element

#_input_value, #_resource, #_text_font, #_type, #even_pages, #odd_pages, #placement, #x_offset, #y_offset

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, placement = ElementPlacement::TOP_LEFT, x_offset = 0, y_offset = 0) ⇒ ImageElement

Initializes a new instance of the ImageElement class.

Parameters:

  • resource (ImageResource)

    |[String] ImageResource object containing the image resource or the name of the image resource.

  • placement (String) (defaults to: ElementPlacement::TOP_LEFT)

    The placement of the image on the page.

  • x_offset (float) (defaults to: 0)

    X coordinate of the image.

  • y_offset (float) (defaults to: 0)

    Y coordinate of the image.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ruby_client/Elements/ImageElement.rb', line 19

def initialize(resource, placement= ElementPlacement::TOP_LEFT, x_offset = 0, y_offset = 0)
  super()
  @_type = ElementType::IMAGE
  @_resource = nil
  @_resource_name = nil

  if resource.is_a?(String)
    @_resource_name = resource
  else
    # super()
    @_resource = resource
    @_resource_name = resource.resource_name
  end

  @placement = placement
  @x_offset = x_offset
  @y_offset = y_offset
end

Instance Attribute Details

#_resource_nameObject

Returns the value of attribute _resource_name.



57
58
59
# File 'lib/ruby_client/Elements/ImageElement.rb', line 57

def _resource_name
  @_resource_name
end

#max_heightObject

Gets or sets the maximum height of the image.



72
73
74
# File 'lib/ruby_client/Elements/ImageElement.rb', line 72

def max_height
  @max_height
end

#max_widthObject

Gets or sets the maximum width of the image.



77
78
79
# File 'lib/ruby_client/Elements/ImageElement.rb', line 77

def max_width
  @max_width
end

#scale_xObject

Gets or sets the horizontal scale of the image.



62
63
64
# File 'lib/ruby_client/Elements/ImageElement.rb', line 62

def scale_x
  @scale_x
end

#scale_yObject

Gets or sets the vertical scale of the image.



67
68
69
# File 'lib/ruby_client/Elements/ImageElement.rb', line 67

def scale_y
  @scale_y
end

Class Method Details

.create_image_element(resource_name, placement, x_offset = 0, y_offset = 0) ⇒ Object

Initializes a new instance of the ImageElement class.

Parameters:

  • resourceName (String)

    The name of the image resource.

  • placement (String)

    The placement of the image on the page.

  • x_offset (float) (defaults to: 0)

    X coordinate of the image.

  • y_offset (float) (defaults to: 0)

    Y coordinate of the image.

Returns:

  • ImageElement returns ImageElement object.



48
49
50
51
52
53
54
55
# File 'lib/ruby_client/Elements/ImageElement.rb', line 48

def self.create_image_element(resource_name, placement, x_offset = 0, y_offset = 0)
  image_element = new ImageElement(nil, nil)
  image_element._resource_name = resource_name
  image_element.placement = placement
  image_element.x_offset = x_offset
  image_element.y_offset = y_offset
  image_element
end

Instance Method Details

#to_json(_options = {}) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ruby_client/Elements/ImageElement.rb', line 79

def to_json(_options = {})
  json_array = {}
  json_array['type'] = 'image'

  json_array['resourceName'] = @_resource_name unless @_resource_name.nil?

  json_array['scaleX'] = @scale_x unless @scale_x.nil?

  json_array['scaleY'] = @scale_y unless @scale_y.nil?

  json_array['maxHeight'] = @max_height unless @max_height.nil?

  json_array['maxWidth'] = @max_width unless @max_width.nil?

  # ---------------------------------

  json_array['placement'] = @placement unless @placement.nil?

  json_array['xOffset'] = @x_offset unless @x_offset.nil?

  json_array['yOffset'] = @y_offset unless @y_offset.nil?

  json_array['evenPages'] = @even_pages unless @even_pages.nil?

  json_array['oddPages'] = @odd_pages unless @odd_pages.nil?

  JSON.pretty_generate(json_array)
end