Class: Panache::Rule
- Inherits:
-
Object
- Object
- Panache::Rule
- Defined in:
- lib/panache.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
- #check(line) ⇒ Object
-
#initialize(regexes, message) ⇒ Rule
constructor
A new instance of Rule.
Constructor Details
#initialize(regexes, message) ⇒ Rule
Returns a new instance of Rule.
13 14 15 16 |
# File 'lib/panache.rb', line 13 def initialize(regexes, ) @regexes = regexes @message = end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
12 13 14 |
# File 'lib/panache.rb', line 12 def @message end |
Instance Method Details
#check(line) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/panache.rb', line 18 def check(line) offset = 0 violations = [] @regexes.each do |regex| while (match = regex.match(line, offset)) # If the match size is 1, then the user did not provide any captures in their regex and we only know # that there is >= 1 violation of the rule in this line. if match.size == 1 return [Violation.new(nil, line, nil, nil, self)] end offset = match.offset(1)[0] violations << Violation.new(nil, line, offset, nil, self) offset += 1 end end violations end |