Class: Prune::Shapes::Base

Inherits:
Object
  • Object
show all
Includes:
Errors, Functions
Defined in:
lib/prune/shapes/base.rb

Direct Known Subclasses

Line, Rectangle, TextBox

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Functions

#mm_to_pt, #pt_to_mm

Constructor Details

#initialize(page) ⇒ Base

Initialize.

Raises:



16
17
18
19
20
21
22
23
24
25
# File 'lib/prune/shapes/base.rb', line 16

def initialize(page)
  @page = page
  @document = @page.document
  raise DuplicateIdError if @page.shape_ids.include?(id)
  @id = "shape_#{@page.shape_ids.size}".to_sym
  @x = 0.0
  @y = 0.0
  @width = 0.0
  @height = 0.0
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



13
14
15
# File 'lib/prune/shapes/base.rb', line 13

def height
  @height
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/prune/shapes/base.rb', line 9

def id
  @id
end

#widthObject

Returns the value of attribute width.



12
13
14
# File 'lib/prune/shapes/base.rb', line 12

def width
  @width
end

#xObject

Returns the value of attribute x.



10
11
12
# File 'lib/prune/shapes/base.rb', line 10

def x
  @x
end

#yObject

Returns the value of attribute y.



11
12
13
# File 'lib/prune/shapes/base.rb', line 11

def y
  @y
end

Instance Method Details

#render(stream) ⇒ Object

Render shapes.



28
29
30
31
32
33
# File 'lib/prune/shapes/base.rb', line 28

def render(stream)
  stream.each{|line| @page.stream << line}
  @page.shape_ids << @id
  @page.shapes.update(@id => self)
  self
end