Sha256: b516d4a518d0e8747f029b756e4c14e129945d550f284226726925cf132ae44f

Contents?: true

Size: 782 Bytes

Versions: 1

Compression:

Stored size: 782 Bytes

Contents

module Logicle
  class TgfWriter
    def initialize(filename, circuit)
      @output_file = File.open(filename, "w")
      @circuit = circuit
    end

    def write
      @circuit.nodes.values.each { |node| write_node(node) }

      write_separator

      @circuit.edges.each { |start, finish| write_edge(start, finish) }
    end

    private
    def write_node(node)
      id = node.id
      type = case node.type
      when :on, :off 
        "SWITCH"
      else 
         node.type.to_s.upcase
      end
      state = node.state ? "ON" : "OFF"

      @output_file.puts "#{ id } #{ type } (#{ state })"
    end

    def write_separator
      @output_file.puts "#"
    end

    def write_edge(start_id, end_id)
      @output_file.puts "#{ start_id } #{ end_id }"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logicle-0.1.0 lib/logicle/tgf_writer.rb