Class: Tailor::Rulers::MaxLineLengthRuler

Inherits:
Tailor::Ruler show all
Defined in:
lib/tailor/rulers/max_line_length_ruler.rb

Instance Attribute Summary

Attributes inherited from Tailor::Ruler

#lexer_observers

Instance Method Summary collapse

Methods inherited from Tailor::Ruler

#add_child_ruler, #problem_type, #problems

Methods included from Logger::Mixin

included

Constructor Details

#initialize(config, options) ⇒ MaxLineLengthRuler

Returns a new instance of MaxLineLengthRuler.



6
7
8
9
# File 'lib/tailor/rulers/max_line_length_ruler.rb', line 6

def initialize(config, options)
  super(config, options)
  add_lexer_observers :ignored_nl, :nl
end

Instance Method Details

#ignored_nl_update(lexed_line, lineno, column) ⇒ Object



11
12
13
14
# File 'lib/tailor/rulers/max_line_length_ruler.rb', line 11

def ignored_nl_update(lexed_line, lineno, column)
  log "<#{self.class}> Line length: #{lexed_line.line_length}"
  measure(lexed_line, lineno, column)
end

#measure(lexed_line, lineno, column) ⇒ Object

Checks to see if the line has more characters that given at @config.

Parameters:

  • lexed_line (Fixnum)

    The line to measure.

  • lineno (Fixnum)

    Line the potential problem is on.

  • column (Fixnum)

    Column the potential problem is on



25
26
27
28
29
30
31
32
33
# File 'lib/tailor/rulers/max_line_length_ruler.rb', line 25

def measure(lexed_line, lineno, column)
  if lexed_line.line_length > @config
    msg = "Line is #{lexed_line.line_length} chars long, "
    msg << "but should be #{@config}."

    @problems << Problem.new(problem_type, lineno, column, msg,
      @options[:level])
  end
end

#nl_update(lexed_line, lineno, column) ⇒ Object



16
17
18
# File 'lib/tailor/rulers/max_line_length_ruler.rb', line 16

def nl_update(lexed_line, lineno, column)
  ignored_nl_update(lexed_line, lineno, column)
end