Class: GitStatistics::RegexMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/git_statistics/regex_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regex, expected_change_count) ⇒ RegexMatcher

Returns a new instance of RegexMatcher.


5
6
7
8
# File 'lib/git_statistics/regex_matcher.rb', line 5

def initialize(regex, expected_change_count)
  @regex = regex
  @expected_change_count = expected_change_count
end

Instance Attribute Details

#expected_change_countObject (readonly)

Returns the value of attribute expected_change_count.


4
5
6
# File 'lib/git_statistics/regex_matcher.rb', line 4

def expected_change_count
  @expected_change_count
end

#regexObject (readonly)

Returns the value of attribute regex.


4
5
6
# File 'lib/git_statistics/regex_matcher.rb', line 4

def regex
  @regex
end

Instance Method Details

#if_matches(line) ⇒ Object


14
15
16
17
18
19
20
21
# File 'lib/git_statistics/regex_matcher.rb', line 14

def if_matches(line)
  changes = self.scan(line)
  if changes && changes.size == expected_change_count
    yield changes
  else
    {}
  end
end

#scan(line) ⇒ Object


10
11
12
# File 'lib/git_statistics/regex_matcher.rb', line 10

def scan(line)
  line.scan(regex).first || []
end