Class: MethodChainingLimit

Inherits:
Object
  • Object
show all
Defined in:
lib/rules/method_chaining_limit.rb

Instance Method Summary collapse

Constructor Details

#initialize(max) ⇒ MethodChainingLimit

Returns a new instance of MethodChainingLimit.



2
3
4
# File 'lib/rules/method_chaining_limit.rb', line 2

def initialize(max)
  @max = max
end

Instance Method Details

#messageObject



12
13
14
# File 'lib/rules/method_chaining_limit.rb', line 12

def message
  "more than one dot per line"
end

#valid?(code) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
# File 'lib/rules/method_chaining_limit.rb', line 6

def valid?(code)
  code.gsub(/\d+\.\d+/,'').split("\n").all? do |line|
    line.count('.') <= @max
  end
end