Sha256: 170b57cff2107b5ec12e41ae546397649c0bffb9eaa2b6c7468d0dfc3a1cf3ce

Contents?: true

Size: 761 Bytes

Versions: 4

Compression:

Stored size: 761 Bytes

Contents

module SandiMeter
  class RulesChecker
    def initialize(data, config)
      @config = config
      @rules = []
      @rules << percentage(data[:first_rule][:small_classes_amount], data[:first_rule][:total_classes_amount])
      @rules << percentage(data[:second_rule][:small_methods_amount], data[:second_rule][:total_methods_amount])
      @rules << percentage(data[:third_rule][:proper_method_calls], data[:third_rule][:total_method_calls])
      @rules << percentage(data[:fourth_rule][:proper_controllers_amount], data[:fourth_rule][:total_controllers_amount])
    end

    def ok?
      @rules.reduce(:+) / 4 > @config[:threshold]
    end

    private
    def percentage(amount, total)
      total > 0 ? (amount / total.to_f)*100 : 100
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sandi_meter-1.1.8 lib/sandi_meter/rules_checker.rb
sandi_meter-1.1.7 lib/sandi_meter/rules_checker.rb
sandi_meter-1.1.6 lib/sandi_meter/rules_checker.rb
sandi_meter-1.1.5 lib/sandi_meter/rules_checker.rb