Sha256: 0dce7ebe6637a4a91011aadb4555fcd06d2ff4098c4cfb6e8335574e9fb19186

Contents?: true

Size: 965 Bytes

Versions: 18

Compression:

Stored size: 965 Bytes

Contents

module CC::Service::QualityHelper
  def improved?
    remediation_cost < previous_remediation_cost
  end

  def constant_name
    payload["constant_name"]
  end

  def quality_title
    if payload["rating"].present?
      "Refactor #{constant_name} from #{rating} on Code Climate"
    else
      "Refactor #{constant_name} on Code Climate"
    end
  end

  def rating
    with_article(payload["rating"])
  end

  def previous_rating
    with_article(payload["previous_rating"])
  end

  def remediation_cost
    payload.fetch("remediation_cost", 0)
  end

  def previous_remediation_cost
    payload.fetch("previous_remediation_cost", 0)
  end

  def with_article(letter, bold = false)
    letter ||= "?"

    text = bold ? "*#{letter}*" : letter
    if %w[A F].include?(letter.to_s)
      "an #{text}"
    else
      "a #{text}"
    end
  end

  def constant_basename(name)
    if name.include?(".")
      File.basename(name)
    else
      name
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
codeclimate-services-1.11.4 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.11.3 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.11.2 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.11.1 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.11.0 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.10.1 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.10.0 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.9.8 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.9.7 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.9.6 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.9.5 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.9.4 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.9.3 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.9.2 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.9.1 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.9.0 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.8.0 lib/cc/helpers/quality_helper.rb
codeclimate-services-1.7.0 lib/cc/helpers/quality_helper.rb