Class: Exercism::Analyzers::Analyzer
- Inherits:
-
Object
- Object
- Exercism::Analyzers::Analyzer
- Defined in:
- lib/exercism-analysis/analyzers/analyzer.rb
Direct Known Subclasses
ControlFlow, EnumerableCondition, ForLoop, Golint, Indentation, IterMutation, Jslint, Kibit, Output, Pylint, Range, Roodi, Send, Shebang, Tab
Defined Under Namespace
Classes: Feedback, Result, ThirdPartyResult
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#processor ⇒ Object
readonly
Returns the value of attribute processor.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(adapter) ⇒ Analyzer
constructor
A new instance of Analyzer.
- #lines ⇒ Object
- #padding(exp) ⇒ Object
- #with_tempfile(name, &block) ⇒ Object
Constructor Details
#initialize(adapter) ⇒ Analyzer
Returns a new instance of Analyzer.
16 17 18 |
# File 'lib/exercism-analysis/analyzers/analyzer.rb', line 16 def initialize(adapter) @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
14 15 16 |
# File 'lib/exercism-analysis/analyzers/analyzer.rb', line 14 def adapter @adapter end |
#processor ⇒ Object (readonly)
Returns the value of attribute processor.
14 15 16 |
# File 'lib/exercism-analysis/analyzers/analyzer.rb', line 14 def processor @processor end |
Class Method Details
.processor(klass) ⇒ Object
8 9 10 11 12 |
# File 'lib/exercism-analysis/analyzers/analyzer.rb', line 8 def self.processor(klass) define_method(:processor) do @processor ||= klass.new end end |
Instance Method Details
#lines ⇒ Object
47 48 49 |
# File 'lib/exercism-analysis/analyzers/analyzer.rb', line 47 def lines adapter.code.lines.zip(1..Float::INFINITY).reject {|(line, _)| line.lstrip.empty? } end |
#padding(exp) ⇒ Object
43 44 45 |
# File 'lib/exercism-analysis/analyzers/analyzer.rb', line 43 def padding(exp) ' ' * exp.column end |
#with_tempfile(name, &block) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/exercism-analysis/analyzers/analyzer.rb', line 34 def with_tempfile(name, &block) temp_file = Tempfile.new(name) temp_file.write(adapter.code) temp_file.flush result = block.call(temp_file) temp_file.unlink result end |