Sha256: 1dba4f647fd4c67044257a8c91d374a7d8bf7527231c554b8b504bf24e6a8658

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents


module Luobo
  class Driver 
    
    ## implements the factory pattern
    @@drivers = {}

    def self.create type
      c = @@drivers[type.to_sym]
      raise "No registered driver for type #{type.to_s}" unless c
      c.new
    end
  
    def self.register_driver type
      raise "Driver for #{type.to_s} already registed." if @@drivers[type.to_sym]
      @@drivers[type.to_sym] = self
    end

    ## cross-drivers methods and callbacks
    def convert token
      pname = "do_" + token.processor_name.downcase
      if self.respond_to?(pname)
        self.send(pname.to_sym, token)
      else
        self.do__missing(token)
      end
    end

    def dump output, contents
      output.print contents if contents
    end

    def exit; end
    def setup; end

    def indent token
      " " * token.indent_level
    end

    def do__raw token
      if token.line_code.size > 0
        indent(token) + token.line_code.gsub(/^\s*/, "") + "\n"
      else
        ""
      end
    end

    def do__missing token
      src = indent(token) + token.line
      src += token.block_code + "\n" if token.block_code
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
luobo-0.1.3 backup/lib/luobo/driver.rb
luobo-0.1.2 backup/lib/luobo/driver.rb
luobo-0.0.5 backup/lib/luobo/driver.rb
luobo-0.1.0 backup/lib/luobo/driver.rb
luobo-0.0.2 lib/luobo/driver.rb