Class: Exercism::Analyzers::Tab

Inherits:
Analyzer
  • Object
show all
Defined in:
lib/exercism-analysis/analyzers/ruby/tab.rb

Constant Summary collapse

TAB_REGEX =
/\A\s*\t+\s*\b/
SPACE_REGEX =
/\A\t* \t*\b/

Instance Attribute Summary

Attributes inherited from Analyzer

#adapter, #processor

Instance Method Summary collapse

Methods inherited from Analyzer

#initialize, #lines, #padding, processor, #with_tempfile

Constructor Details

This class inherits a constructor from Exercism::Analyzers::Analyzer

Instance Method Details

#callObject



9
10
11
# File 'lib/exercism-analysis/analyzers/ruby/tab.rb', line 9

def call
  Result.new(:indentation, feedback)
end

#feedbackObject



13
14
15
16
17
# File 'lib/exercism-analysis/analyzers/ruby/tab.rb', line 13

def feedback
  feedback_lines_with_type.take(1).map do |(line, line_no), type|
    Feedback.from_line(type, line.chomp, line_no)
  end
end

#feedback_lines_with_typeObject



19
20
21
# File 'lib/exercism-analysis/analyzers/ruby/tab.rb', line 19

def feedback_lines_with_type
  lines_with_tabs_and_spaces.zip([:tab_and_space]) + lines_with_tabs.zip([:tab])
end

#lines_with_tabsObject



23
24
25
26
27
# File 'lib/exercism-analysis/analyzers/ruby/tab.rb', line 23

def lines_with_tabs
  lines.select do |line, _|
    line =~ TAB_REGEX
  end
end

#lines_with_tabs_and_spacesObject



29
30
31
32
33
# File 'lib/exercism-analysis/analyzers/ruby/tab.rb', line 29

def lines_with_tabs_and_spaces
  lines_with_tabs.select do |line, _|
    line =~ SPACE_REGEX
  end
end