Module: CC::Service::QualityHelper

Included in:
Slack
Defined in:
lib/cc/helpers/quality_helper.rb

Instance Method Summary collapse

Instance Method Details

#constant_basename(name) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/cc/helpers/quality_helper.rb', line 45

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

#constant_nameObject



6
7
8
# File 'lib/cc/helpers/quality_helper.rb', line 6

def constant_name
  payload["constant_name"]
end

#improved?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/cc/helpers/quality_helper.rb', line 2

def improved?
  remediation_cost < previous_remediation_cost
end

#previous_ratingObject



22
23
24
# File 'lib/cc/helpers/quality_helper.rb', line 22

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

#previous_remediation_costObject



30
31
32
# File 'lib/cc/helpers/quality_helper.rb', line 30

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

#quality_titleObject



10
11
12
13
14
15
16
# File 'lib/cc/helpers/quality_helper.rb', line 10

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

#ratingObject



18
19
20
# File 'lib/cc/helpers/quality_helper.rb', line 18

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

#remediation_costObject



26
27
28
# File 'lib/cc/helpers/quality_helper.rb', line 26

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

#with_article(letter, bold = false) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/cc/helpers/quality_helper.rb', line 34

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