Class: BloodContracts::Contracts::Statistics

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/blood_contracts/contracts/statistics.rb

Instance Method Summary collapse

Instance Method Details

#found_unexpected_behavior?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/blood_contracts/contracts/statistics.rb', line 23

def found_unexpected_behavior?
  storage.key?(Storage::UNDEFINED_RULE)
end

#store(rule) ⇒ Object



8
9
10
# File 'lib/blood_contracts/contracts/statistics.rb', line 8

def store(rule)
  storage[rule] += 1
end

#to_hObject



12
13
14
# File 'lib/blood_contracts/contracts/statistics.rb', line 12

def to_h
  Hash[storage.map { |rule_name, times| [rule_name, rule_stats(times)] }]
end

#to_sObject



16
17
18
19
20
21
# File 'lib/blood_contracts/contracts/statistics.rb', line 16

def to_s
  to_h.map do |name, occasions|
    " - '#{name}' happened #{occasions.times} time(s) "\
    "(#{(occasions.percent * 100).round(2)}% of the time)"
  end.join("; \n")
end