Class: Cards::DotWriter

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

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ DotWriter

Returns a new instance of DotWriter.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/cards/writers/dot_writer.rb', line 3

def initialize(file)
  if file.respond_to? :puts
    @file = file
  else
    @file = File.open(file + ".dot", "w")
  end
  @node_color = {:green => "darkseagreen1", :blue => "lightblue", :red => "pink", :yellow => "lightyellow"}
  @nodes = []

  puts "digraph G {"
  puts "graph [nodesep=.1, ranksep=.1, ordering=out];"
  puts "node [shape=box, color=black, style=filled, width=2, height=1.2, fixedsize=true, labeljust=\"l\"];"
  puts "edge [style=invis, weight=1];"
end

Instance Method Details

#create_card(name, color, position) ⇒ Object



22
23
24
# File 'lib/cards/writers/dot_writer.rb', line 22

def create_card(name, color, position)
  create_node("card", position, %{label="#{wrap(name)}",fillcolor=#{@node_color[color]}})
end

#doneObject



26
27
28
29
30
31
32
# File 'lib/cards/writers/dot_writer.rb', line 26

def done
  create_gap_nodes
  create_ranks
  create_edges
  puts "}"
  @file.close
end

#puts(string) ⇒ Object



18
19
20
# File 'lib/cards/writers/dot_writer.rb', line 18

def puts(string)
  @file.puts string
end