Class: DynamicPDFApi::RectangleElement

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

Overview

Represents a rectangle page element.

This class can be used to place rectangles of any size or color 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

Instance Method Summary collapse

Constructor Details

#initialize(width, height, placement = ElementPlacement::TOP_LEFT) ⇒ RectangleElement

Initializes a new instance of the RectangleElement class.

Parameters:

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

    The placement of the rectangle on the page.

  • width (float)

    Width of the rectangle.

  • height (float)

    Height of the rectangle.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby_client/Elements/RectangleElement.rb', line 19

def initialize(width, height,placement= ElementPlacement::TOP_LEFT)
  super()
  @_type = ElementType::RECTANGLE
  @border_width = nil
  @corner_radius = nil
  @border_style = nil
  @border_color = nil
  @fill_color = nil

  @placement = placement
  @width = width
  @height = height
end

Instance Attribute Details

#border_colorObject

Gets or sets the Color object to use for the border of the rectangle.



61
62
63
# File 'lib/ruby_client/Elements/RectangleElement.rb', line 61

def border_color
  @border_color
end

#border_styleObject

Gets or sets the LineStyle object used to specify the border style of the rectangle.



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

def border_style
  @border_style
end

#border_widthObject

Gets or sets the border width of the rectangle.

To force the borders not to appear set the border width to any value 0 or less.



48
49
50
# File 'lib/ruby_client/Elements/RectangleElement.rb', line 48

def border_width
  @border_width
end

#corner_radiusObject

Gets or sets the corner radius of the rectangle.



53
54
55
# File 'lib/ruby_client/Elements/RectangleElement.rb', line 53

def corner_radius
  @corner_radius
end

#fill_colorObject

Gets or sets the Color object to use for the fill of the rectangle.

To force no color to appear in the rectangle (only borders) set the fill color to nil (Nothing in Visual Basic).



68
69
70
# File 'lib/ruby_client/Elements/RectangleElement.rb', line 68

def fill_color
  @fill_color
end

#heightObject

Gets or sets the height of the rectangle.



41
42
43
# File 'lib/ruby_client/Elements/RectangleElement.rb', line 41

def height
  @height
end

#widthObject

Gets or sets the width of the rectangle.



36
37
38
# File 'lib/ruby_client/Elements/RectangleElement.rb', line 36

def width
  @width
end

Instance Method Details

#to_json(_options = {}) ⇒ Object



70
71
72
73
74
75
76
77
78
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
107
# File 'lib/ruby_client/Elements/RectangleElement.rb', line 70

def to_json(_options = {})
  # 'width':100.0,'height':50.0,'cornerRadius':0.0,'placement':'topCenter','xOffset':0.0,'yOffset':0.0
  json_array = {}
  json_array['type'] = 'rectangle'

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

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

  json_array['borderWidth'] = @border_width unless @border_width.nil?

  json_array['cornerRadius'] = @corner_radius unless @corner_radius.nil?

  json_array['fillColor'] = @fill_color._color_string if !@fill_color.nil? && !@fill_color._color_string.nil?

  if !@border_style.nil? && !@border_style._line_style_string.nil?
    json_array['borderStyle'] = @border_style._line_style_string
  end

  if !@border_color.nil? && !@border_color._color_string.nil?
    json_array['borderColor'] =
      @border_color._color_string
  end

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

  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