Class: Cards::GraffleWriter

Inherits:
Object show all
Defined in:
lib/cards/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", omnigraffle_app = "OmniGraffle 4") ⇒ GraffleWriter

Returns a new instance of GraffleWriter.



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

def initialize(name = "Card Wall", omnigraffle_app = "OmniGraffle 4")
  @app = Appscript.app(omnigraffle_app)
  @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



63
64
65
# File 'lib/cards/graffle_writer.rb', line 63

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

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



19
20
21
# File 'lib/cards/graffle_writer.rb', line 19

def app
  @app
end

Instance Method Details

#canvasObject



59
60
61
# File 'lib/cards/graffle_writer.rb', line 59

def canvas
  @doc.canvases[0]
end

#clear_shapesObject



39
40
41
42
43
# File 'lib/cards/graffle_writer.rb', line 39

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

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



45
46
47
48
49
50
51
52
53
54
# File 'lib/cards/graffle_writer.rb', line 45

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



56
57
# File 'lib/cards/graffle_writer.rb', line 56

def done
end

#open_document(name) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/cards/graffle_writer.rb', line 30

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