Sha256: 33e79e473f635c1c55b9dbe9aa83ebf7e4094fde1a74662a41a360a893861bd2

Contents?: true

Size: 931 Bytes

Versions: 1

Compression:

Stored size: 931 Bytes

Contents

# encoding: utf-8

require 'strike/table'

class Strike
  class Interpreter
    attr_reader :tables

    def initialize(table_source = nil)
      @table_source = table_source
      @tables ||= Hash.new { |h, k| h[k] = :keep }
    end

    # Parse the given profile and generate the tables defined in it.
    #
    # @param [String] profile the profile with the definitions.
    # @return [Hash] all the tables defined in the profile.
    def parse(profile)
      instance_eval(profile)
      tables
    end

    # Define a table and its tables.
    #
    # @param [String, Symbol] name the name of the table.
    # @param [Proc] block the block to declare the definitions for the tables.
    def table(name, &block)
      table = table_source.call(&block)

      @tables[name.to_sym] = table.call
    end

    def table_source
      @table_source ||= Strike::Table.public_method(:new)
    end
    protected :table_source
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
strike-0.4.0 lib/strike/interpreter.rb