Sha256: f23fccec1909eec2efc1fd9153143a299de0fc10e9144edde758665d0db5a001

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

require 'erb'

module Xcov
  class Base

    attr_accessor :name
    attr_accessor :coverage
    attr_accessor :displayable_coverage
    attr_accessor :coverage_color

    attr_accessor :id

    def create_displayable_coverage
      "%.0f%%" % [(@coverage*100)]
    end

    def create_coverage_color
      if @coverage > 0.8
        return "#1FCB32"
      elsif @coverage > 0.65
        return "#FCFF00"
      elsif @coverage > 0.5
        return "#FF9C00"
      else
        return "#FF0000"
      end
    end

    def create_summary
      if @coverage > 0.8
        return "Overall coverage is good"
      elsif @coverage > 0.65
        return "There is room for improvement"
      elsif @coverage > 0.5
        return "Almost unmaintainable"
      else
        return "Keep calm and leave the boat"
      end
    end

    # Class methods
    def self.template(name)
      ERB.new(File.read(File.join(File.dirname(__FILE__), "../../../views/", "#{name}.erb")))
    end

    def self.create_id(name)
      char_map = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
      random = (0...50).map { char_map[rand(char_map.length)] }.join
      pre_hash = "#{random}_#{name}"
      Digest::SHA1.hexdigest(pre_hash)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
xcov-0.5 lib/xcov/model/base.rb
xcov-0.4 lib/xcov/model/base.rb
xcov-0.3 lib/xcov/model/base.rb
xcov-0.2 lib/xcov/model/base.rb