Class: Logicle::TgfReader

Inherits:
Object
  • Object
show all
Defined in:
lib/logicle/tgf_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ TgfReader

Returns a new instance of TgfReader.



3
4
5
6
7
8
9
# File 'lib/logicle/tgf_reader.rb', line 3

def initialize(input)
  if File.exists?(input)
    @contents = File.readlines(input)    # read file for TGF content
  else
    @contents = input.lines              # use string param as TGF content
  end
end

Instance Method Details

#parseObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/logicle/tgf_reader.rb', line 11

def parse
  @circuit = Digraph.new
  still_reading_nodes = true

  @contents.each do |line|
    line.chomp!

    if line =~ /\A#/
      still_reading_nodes = false
    elsif still_reading_nodes
      node_directive(line)
    else
      edge_directive(line)
    end
  end

  @circuit
end