class BELParser::Script::StateAggregator
StateAggregator
aggregates BEL
Script
state for each {BELParser::Parsers::AST::Node AST
node} it processes.
Constants
- STATE_PATH
Public Class Methods
new(ast_enum, options = {})
click to toggle source
# File lib/bel_parser/script/state_aggregator.rb, line 9 def initialize(ast_enum, options = {}) @ast_enum = ast_enum @script_context = {}.merge(options) StateAggregator.require_script_path @state_functions = StateAggregator.state_constants(State) end
require_script_path()
click to toggle source
# File lib/bel_parser/script/state_aggregator.rb, line 32 def self.require_script_path base_path = File.expand_path(File.dirname(__FILE__)) + File::SEPARATOR Dir[File.join(base_path, STATE_PATH, '*.rb')] .each do |ruby_file| ruby_file.sub!(/^#{Regexp.escape(base_path)}/, '') require_relative ruby_file end end
state_constants(mod)
click to toggle source
# File lib/bel_parser/script/state_aggregator.rb, line 41 def self.state_constants(mod) mod.constants.collect do |symbol| const = mod.const_get(symbol) const if const.respond_to?(:consume) end.compact end
Public Instance Methods
each() { |line_number, line, ast_node, script_context| ... }
click to toggle source
# File lib/bel_parser/script/state_aggregator.rb, line 17 def each if block_given? @ast_enum.each do |(line_number, line, ast_node)| ast_node.traverse.each do |node| @state_functions.each do |func| func.consume(node, @script_context) end end yield [line_number, line, ast_node, @script_context] end else enum_for(:each) end end