Class: Gitt::Sanitizers::Statistic
- Inherits:
-
Object
- Object
- Gitt::Sanitizers::Statistic
- Defined in:
- lib/gitt/sanitizers/statistic.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(empty: EMPTY, pattern: PATTERN) ⇒ Statistic
constructor
A new instance of Statistic.
Constructor Details
Class Method Details
.update_stats(attributes, kind, total) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/gitt/sanitizers/statistic.rb', line 15 def self.update_stats 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/statistic.rb', line 29 def call text return empty unless text text.scan(pattern).each.with_object(empty.dup) do |(number, kind), aggregate| self.class.update_stats aggregate, kind, number.to_i end end |