Class: BloodContracts::Contracts::Description

Inherits:
Object
  • Object
show all
Defined in:
lib/blood_contracts/contracts/description.rb

Class Method Summary collapse

Class Method Details

.call(contract_hash) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/blood_contracts/contracts/description.rb', line 4

def self.call(contract_hash)
  Hashie::Mash.new(contract_hash).map do |name, rule|
    rule_description = " - '#{name}' "
    if rule.threshold
      rule_description << <<~TEXT
        in more then #{(rule.threshold * 100).round(2)}% of cases;
      TEXT
    elsif rule.limit
      rule_description << <<~TEXT
        in less then #{(rule.limit * 100).round(2)}% of cases;
      TEXT
    else
      rule_description << <<~TEXT
        in any number of cases;
      TEXT
    end
    rule_description
  end.compact.join
end