Class: Exercism::Processors::IndentationProcessor

Inherits:
Processor
  • Object
show all
Defined in:
lib/exercism-analysis/processors/indentation_processor.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Processor

#find_exp, #find_exps

Constructor Details

#initializeIndentationProcessor

Returns a new instance of IndentationProcessor.



18
19
20
# File 'lib/exercism-analysis/processors/indentation_processor.rb', line 18

def initialize
  @inconsistent_nodes = []
end

Class Method Details

.inconsistent_end(*events) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/exercism-analysis/processors/indentation_processor.rb', line 6

def self.inconsistent_end(*events)
  events.each do |event|
    define_method "process_#{event}" do |exp|
      if inconsistent_end?(exp)
        @inconsistent_nodes << exp
      end
    end
  end
end

Instance Method Details

#process_begin(exp) ⇒ Object



40
41
42
43
44
# File 'lib/exercism-analysis/processors/indentation_processor.rb', line 40

def process_begin(exp)
  if inconsistent_end?(exp) || [exp.rescue, exp.ensure].compact.any? {|e| inconsistent?(exp, e)}
    @inconsistent_nodes << exp
  end
end

#process_case(exp) ⇒ Object



34
35
36
37
38
# File 'lib/exercism-analysis/processors/indentation_processor.rb', line 34

def process_case(exp)
  if inconsistent_end?(exp) || inconsistent_when?(exp)
    @inconsistent_nodes << exp
  end
end

#process_if(exp) ⇒ Object Also known as: process_elsif



26
27
28
29
30
# File 'lib/exercism-analysis/processors/indentation_processor.rb', line 26

def process_if(exp)
  if inconsistent_end?(exp) || (exp.else_statement && inconsistent?(exp, exp.else_statement))
    @inconsistent_nodes << exp
  end
end

#resultObject



22
23
24
# File 'lib/exercism-analysis/processors/indentation_processor.rb', line 22

def result
  @inconsistent_nodes.select(&method(:multiple_lines?))
end