Class: Uniword::Redact::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/redact/result.rb

Overview

Aggregated redaction result.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResult

Returns a new instance of Result.



9
10
11
# File 'lib/uniword/redact/result.rb', line 9

def initialize
  @by_pattern = Hash.new { |h, k| h[k] = 0 }
end

Instance Attribute Details

#by_patternObject (readonly)

Returns the value of attribute by_pattern.



7
8
9
# File 'lib/uniword/redact/result.rb', line 7

def by_pattern
  @by_pattern
end

Instance Method Details

#add(name, count) ⇒ void

This method returns an undefined value.

Parameters:

  • name (Symbol)

    pattern name

  • count (Integer)

    substitutions for this pattern



16
17
18
# File 'lib/uniword/redact/result.rb', line 16

def add(name, count)
  @by_pattern[name] += count
end

#countInteger

Total substitutions across all patterns.

Returns:

  • (Integer)


23
24
25
# File 'lib/uniword/redact/result.rb', line 23

def count
  @by_pattern.values.sum
end

#empty?Boolean

True when zero substitutions were made.

Returns:

  • (Boolean)


37
38
39
# File 'lib/uniword/redact/result.rb', line 37

def empty?
  count.zero?
end

#patterns_matchedArray<Symbol>

Patterns that matched at least once.

Returns:

  • (Array<Symbol>)


30
31
32
# File 'lib/uniword/redact/result.rb', line 30

def patterns_matched
  @by_pattern.select { |_, c| c.positive? }.keys
end