Class: RubyPost::Picture

Inherits:
Drawable show all
Defined in:
lib/drawable.rb

Overview

wrapper for the metapost picture pictures are collection of drawables

Direct Known Subclasses

SimplePlot

Constant Summary collapse

@@default_name =

store a unique picture name unless incase it was not specified.

0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = "picture_number" + @@default_name.to_s) ⇒ Picture

intialise a picture with it’s name, use a string!



22
23
24
25
26
27
28
# File 'lib/drawable.rb', line 22

def initialize(name="picture_number" + @@default_name.to_s)
  super()
  @name = name
  @draw_commands = Array.new
  @@default_name = @@default_name + 1
  @@picture_precompiler.add_picture(self)
end

Instance Attribute Details

#name=(value) ⇒ Object (writeonly)

Sets the attribute name

Parameters:

  • value

    the value to set the attribute name to.



16
17
18
# File 'lib/drawable.rb', line 16

def name=(value)
  @name = value
end

Instance Method Details

#add_drawable(d) ⇒ Object



30
31
32
# File 'lib/drawable.rb', line 30

def add_drawable(d)
  @draw_commands.push(d)
end

#compileObject



44
45
46
# File 'lib/drawable.rb', line 44

def compile
  @name.compile
end

#precompileObject

creates the definition of the picture that goes at the start of the file



36
37
38
39
40
41
42
# File 'lib/drawable.rb', line 36

def precompile
  str = "picture " + @name + ";\n"
  @draw_commands.each do |d| 
    str = str + d.compile +  "\n"
  end
  str = str + @name + " := currentpicture; currentpicture := " + @@org_picture + ";\n"
end