Class: ImproveYourCode::ContextBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/improve_your_code/context_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(syntax_tree) ⇒ ContextBuilder

Returns a new instance of ContextBuilder.



16
17
18
19
# File 'lib/improve_your_code/context_builder.rb', line 16

def initialize(syntax_tree)
  @syntax_tree = syntax_tree
  @current_context = Context::RootContext.new(syntax_tree)
end

Instance Attribute Details

#syntax_treeObject (readonly)

Returns the value of attribute syntax_tree.



14
15
16
# File 'lib/improve_your_code/context_builder.rb', line 14

def syntax_tree
  @syntax_tree
end

Instance Method Details

#build(exp = syntax_tree, parent_exp = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/improve_your_code/context_builder.rb', line 21

def build(exp = syntax_tree, parent_exp = nil)
  context_processor = "process_#{exp.type}"

  if context_processor_exists?(context_processor)
    send(context_processor, exp, parent_exp)
  else
    process exp
  end

  current_context
end