diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-08-11 14:46:47 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-08-15 14:39:46 +0200 |
commit | 796efcc704558119c1e5cb298d45a4f592662cb7 (patch) | |
tree | 2536fb103fd5e2504377dc7c1a264381cdf9ee65 /lib/gitlab/badge | |
parent | cc244160c5e2ecda2818348cb6b909f1dcb96e44 (diff) | |
download | gitlab-ce-796efcc704558119c1e5cb298d45a4f592662cb7.tar.gz |
Add template class for coverage report badge
Diffstat (limited to 'lib/gitlab/badge')
-rw-r--r-- | lib/gitlab/badge/coverage/template.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/gitlab/badge/coverage/template.rb b/lib/gitlab/badge/coverage/template.rb new file mode 100644 index 00000000000..6f9a38b07dc --- /dev/null +++ b/lib/gitlab/badge/coverage/template.rb @@ -0,0 +1,69 @@ +module Gitlab + module Badge + module Coverage + ## + # Class that represents a coverage badge template. + # + # Template object will be passed to badge.svg.erb template. + # + class Template + STATUS_COLOR = { + good: '#4c1', + acceptable: '#b0c', + medium: '#dfb317', + low: '#e05d44', + unknown: '#9f9f9f' + } + + def initialize(badge) + @entity = badge.entity + @status = badge.status + end + + def key_text + @entity.to_s + end + + def value_text + @status ? "#{@status}%" : 'unknown' + end + + def key_width + 62 + end + + def value_width + @status ? 32 : 58 + end + + def key_color + '#555' + end + + def value_color + case @status + when nil then STATUS_COLOR[:unknown] + when 95..100 then STATUS_COLOR[:good] + when 90..95 then STATUS_COLOR[:acceptable] + when 75..90 then STATUS_COLOR[:medium] + when 0..75 then STATUS_COLOR[:low] + else + STATUS_COLOR[:unknown] + end + end + + def key_text_anchor + key_width / 2 + end + + def value_text_anchor + key_width + (value_width / 2) + end + + def width + key_width + value_width + end + end + end + end +end |