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
# File 'lib/cards/writers/dot_writer.rb', line 3

def initialize(file)
  @file = file
  @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



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

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

#doneObject



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

def done
  create_gap_nodes
  create_ranks
  create_edges
  puts "}"
end

#puts(string) ⇒ Object



14
15
16
# File 'lib/cards/writers/dot_writer.rb', line 14

def puts(string)
  @file.puts string
end