Class: Sugpoko::Component
- Inherits:
-
Object
- Object
- Sugpoko::Component
- Includes:
- Helpers::Prawn
- Defined in:
- lib/sugpoko/component.rb
Instance Attribute Summary collapse
-
#cursor_origin ⇒ Object
readonly
Returns the value of attribute cursor_origin.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#pdf ⇒ Object
readonly
Returns the value of attribute pdf.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #base_attributes ⇒ Object
- #configure(options = {}) ⇒ Object
- #draw(klass, options = {}) ⇒ Object
- #generate ⇒ Object
-
#initialize(options = {}) ⇒ Component
constructor
A new instance of Component.
- #initialize_position(point) ⇒ Object
Methods included from Helpers::Prawn
#bounding_box, #build_bounding_box_options
Constructor Details
#initialize(options = {}) ⇒ Component
25 26 27 28 29 30 31 |
# File 'lib/sugpoko/component.rb', line 25 def initialize( = {}) @pdf = .fetch(:pdf) @width = .fetch(:width) @height = .fetch(:height) initialize_position(.fetch(:position)) configure() end |
Instance Attribute Details
#cursor_origin ⇒ Object (readonly)
Returns the value of attribute cursor_origin.
5 6 7 |
# File 'lib/sugpoko/component.rb', line 5 def cursor_origin @cursor_origin end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/sugpoko/component.rb', line 5 def data @data end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
5 6 7 |
# File 'lib/sugpoko/component.rb', line 5 def height @height end |
#pdf ⇒ Object (readonly)
Returns the value of attribute pdf.
5 6 7 |
# File 'lib/sugpoko/component.rb', line 5 def pdf @pdf end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
5 6 7 |
# File 'lib/sugpoko/component.rb', line 5 def position @position end |
#width ⇒ Object (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_attributes ⇒ Object
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( = {}) # override this for other initialization process end |
#draw(klass, options = {}) ⇒ Object
11 12 13 |
# File 'lib/sugpoko/component.rb', line 11 def draw(klass, = {}) klass.new(base_attributes.merge()).generate end |
#generate ⇒ Object
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 |