Class: Strike::Interpreter

Inherits:
Object
  • Object
show all
Defined in:
lib/strike/interpreter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_source = nil) ⇒ Interpreter

Returns a new instance of Interpreter.



9
10
11
12
# File 'lib/strike/interpreter.rb', line 9

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

Instance Attribute Details

#tablesObject (readonly)

Returns the value of attribute tables.



7
8
9
# File 'lib/strike/interpreter.rb', line 7

def tables
  @tables
end

Instance Method Details

#parse(profile) ⇒ Hash

Parse the given profile and generate the tables defined in it.

Parameters:

  • profile (String)

    the profile with the definitions.

Returns:

  • (Hash)

    all the tables defined in the profile.



18
19
20
21
# File 'lib/strike/interpreter.rb', line 18

def parse(profile)
  instance_eval(profile)
  tables
end

#table(name, &block) ⇒ Object

Define a table and its tables.

Parameters:

  • name (String, Symbol)

    the name of the table.

  • block (Proc)

    the block to declare the definitions for the tables.



27
28
29
30
31
# File 'lib/strike/interpreter.rb', line 27

def table(name, &block)
  table = table_source.call(&block)

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