Class: Sugpoko::Component

Inherits:
Object
  • Object
show all
Includes:
Helpers::Prawn
Defined in:
lib/sugpoko/component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Prawn

#bounding_box, #build_bounding_box_options

Constructor Details

#initialize(options = {}) ⇒ Component

Returns a new instance of Component.



25
26
27
28
29
30
31
# File 'lib/sugpoko/component.rb', line 25

def initialize(options = {})
  @pdf = options.fetch(:pdf)
  @width = options.fetch(:width)
  @height = options.fetch(:height)
  initialize_position(options.fetch(:position))
  configure(options)
end

Instance Attribute Details

#cursor_originObject (readonly)

Returns the value of attribute cursor_origin.



5
6
7
# File 'lib/sugpoko/component.rb', line 5

def cursor_origin
  @cursor_origin
end

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/sugpoko/component.rb', line 5

def data
  @data
end

#heightObject (readonly)

Returns the value of attribute height.



5
6
7
# File 'lib/sugpoko/component.rb', line 5

def height
  @height
end

#pdfObject (readonly)

Returns the value of attribute pdf.



5
6
7
# File 'lib/sugpoko/component.rb', line 5

def pdf
  @pdf
end

#positionObject (readonly)

Returns the value of attribute position.



5
6
7
# File 'lib/sugpoko/component.rb', line 5

def position
  @position
end

#widthObject (readonly)

Returns the value of attribute width.



5
6
7
# File 'lib/sugpoko/component.rb', line 5

def width
  @width
end

Instance Method Details

#base_attributesObject



15
16
17
18
19
20
21
22
23
# File 'lib/sugpoko/component.rb', line 15

def base_attributes
  {
    pdf: pdf,
    width: width,
    height: height,
    position: [0, pdf.cursor],
    data: data
  }
end

#configure(options = {}) ⇒ Object



41
42
43
# File 'lib/sugpoko/component.rb', line 41

def configure(options = {})
  # override this for other initialization process
end

#draw(klass, options = {}) ⇒ Object



11
12
13
# File 'lib/sugpoko/component.rb', line 11

def draw(klass, options = {})
  klass.new(base_attributes.merge(options)).generate
end

#generateObject



7
8
9
# File 'lib/sugpoko/component.rb', line 7

def generate
  raise '#generate not defined'
end

#initialize_position(point) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/sugpoko/component.rb', line 33

def initialize_position(point)
  if point
    @position = Sugpoko::Point.new *point
  else
    @position = Sugpoko::Point.new 0, pdf.cursor
  end
end