Class: Cards::GraffleWriter

Inherits:
Object show all
Defined in:
lib/cards/writers/graffle_writer.rb

Constant Summary collapse

CARD_WALL_STENCIL =
File.expand_path(File.dirname(__FILE__) + "/CardWall.gstencil")
COLORS =
{
  :green => [0xcccc, 0xffff, 0xcccc],
  :red => [0xffff, 0xcccc, 0xcccc],
  :yellow => [0xffff, 0xffff, 0xcccc],
  :blue => [0xcccc, 0xcccc, 0xffff],
  :white => [0xffff, 0xffff, 0xffff]
}
CARD_WIDTH =
2.875.inches
CARD_HEIGHT =
2.875.inches
CARD_PADDING =
0.4.inches

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = "Card Wall") ⇒ GraffleWriter

Returns a new instance of GraffleWriter.



23
24
25
26
27
28
29
30
# File 'lib/cards/writers/graffle_writer.rb', line 23

def initialize(name = "Card Wall")
  @app = Appscript.app('OmniGraffle 4')
  @doc = @app.documents[0]
  puts "opening #{name}"
  open_document(name)
  activate
  clear_shapes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



65
66
67
# File 'lib/cards/writers/graffle_writer.rb', line 65

def method_missing(sym, *args)
  @app.send(sym, *args)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



21
22
23
# File 'lib/cards/writers/graffle_writer.rb', line 21

def app
  @app
end

Instance Method Details

#canvasObject



61
62
63
# File 'lib/cards/writers/graffle_writer.rb', line 61

def canvas
  @doc.canvases[0]
end

#clear_shapesObject



41
42
43
44
45
# File 'lib/cards/writers/graffle_writer.rb', line 41

def clear_shapes
  canvas.shapes.get.each do |shape|
    shape.delete
  end
end

#create_card(text, color = :yellow, cell = [0, 0]) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/cards/writers/graffle_writer.rb', line 47

def create_card(text, color = :yellow, cell = [0, 0])
  canvas.make :new => :shape, 
              :with_properties => {
                :origin => [cell[0] * (CARD_WIDTH + CARD_PADDING),
                            cell[1] * (CARD_HEIGHT + CARD_PADDING)], 
                :size => [CARD_WIDTH, CARD_HEIGHT],
                :fill_color => COLORS[color],
                :text => {:size => 16.0, :text => text}
              }
end

#doneObject



58
59
# File 'lib/cards/writers/graffle_writer.rb', line 58

def done
end

#open_document(name) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/cards/writers/graffle_writer.rb', line 32

def open_document(name)
  @doc = @app.documents[name]
  return @doc if @doc.exists

  @doc = @app.make :new => :document, :with_properties => {:name => name}
  canvas.adjusts_pages.set true
  @app.windows[name].zoom.set 0.2
end