Class: Sketch

Inherits:
Valuable
  • Object
show all
Defined in:
lib/sketch.rb

Defined Under Namespace

Modules: Base Classes: Canvas, Circle, Element, Ellipse, Line, Path, Polygon, Rect, Star, Text, Triangle

Instance Method Summary collapse

Instance Method Details

#draw(canvas) ⇒ Object

Raises:

  • (NotImplementedError)

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

def draw(canvas)
  raise NotImplementedError
end

#svg_attributesObject


27
28
29
30
31
32
33
# File 'lib/sketch.rb', line 27

def svg_attributes
  out = {}
  out[:height]  = self.height if self.height
  out[:width]   = self.width if self.width
  out[:doctype] = self.doctype if self.doctype
  out
end

#svg_builderObject


35
36
37
# File 'lib/sketch.rb', line 35

def svg_builder
  Canvas.new( svg_attributes ).builder {|canvas| yield canvas}
end

#to_htmlObject


21
22
23
24
25
# File 'lib/sketch.rb', line 21

def to_html
  svg_builder do |canvas|
    self.draw( canvas )
  end.doc.root.to_s
end

#to_svgObject


15
16
17
18
19
# File 'lib/sketch.rb', line 15

def to_svg( )
  svg_builder do |canvas|
    self.draw( canvas )
  end.to_xml
end