Class: Gitt::Sanitizers::Statistics
- Inherits:
-
Object
- Object
- Gitt::Sanitizers::Statistics
- Defined in:
- lib/gitt/sanitizers/statistics.rb
Overview
Converts raw text into a statistics hash.
Constant Summary collapse
- EMPTY =
{files_changed: 0, insertions: 0, deletions: 0}.freeze
- PATTERN =
/ (?<total>\d+) # Total capture group. \s # Space delimiter. (?<kind>file|insertion|deletion) # Kind capture group. /x
Class Method Summary collapse
Instance Method Summary collapse
- #call(text) ⇒ Object
-
#initialize(attributes = EMPTY, pattern: PATTERN) ⇒ Statistics
constructor
A new instance of Statistics.
Constructor Details
#initialize(attributes = EMPTY, pattern: PATTERN) ⇒ Statistics
Returns a new instance of Statistics.
24 25 26 27 |
# File 'lib/gitt/sanitizers/statistics.rb', line 24 def initialize attributes = EMPTY, pattern: PATTERN @attributes = attributes @pattern = pattern end |
Class Method Details
.update(attributes, kind, total) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/gitt/sanitizers/statistics.rb', line 15 def self.update attributes, kind, total case kind when "file" then attributes[:files_changed] = total when "insertion" then attributes[:insertions] = total when "deletion" then attributes[:deletions] = total else fail StandardError, "Invalid kind: #{kind.inspect}." end end |
Instance Method Details
#call(text) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/gitt/sanitizers/statistics.rb', line 29 def call text return attributes unless text text.scan(pattern).each.with_object(attributes.dup) do |(number, kind), aggregate| self.class.update aggregate, kind, number.to_i end end |