Class: Strike::Interpreter
- Inherits:
-
Object
- Object
- Strike::Interpreter
- Defined in:
- lib/strike/interpreter.rb
Instance Attribute Summary collapse
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Instance Method Summary collapse
-
#initialize(table_source = nil) ⇒ Interpreter
constructor
A new instance of Interpreter.
-
#parse(profile) ⇒ Hash
Parse the given profile and generate the tables defined in it.
-
#table(name, &block) ⇒ Object
Define a table and its tables.
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
#tables ⇒ Object (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.
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.
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 |