Class: SimpleCov::Formatter::ShieldFormatter::Generators::ShieldsIO

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov-formatter-shield/generators/shields_io.rb

Overview

TODO: Make configurable

Constant Summary collapse

HOST =
'img.shields.io'.freeze
PATH =
'badge'.freeze
EXTENSION =
'png'.freeze
STYLE =
'flat'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ShieldsIO

Returns a new instance of ShieldsIO.



14
15
16
17
# File 'lib/simplecov-formatter-shield/generators/shields_io.rb', line 14

def initialize(options)
  @options = options
  @image = nil
end

Instance Method Details

#build_uriObject



34
35
36
37
38
# File 'lib/simplecov-formatter-shield/generators/shields_io.rb', line 34

def build_uri
  parts = [@options.text, @options.status, @options.color].map { |part| CGI.escape(part.to_s) }
  path = "/#{PATH}/#{parts.join('-')}.#{EXTENSION}"
  return URI::HTTPS.build(host: HOST, path: path, query: "style=#{STYLE}")
end

#generateObject



19
20
21
22
23
# File 'lib/simplecov-formatter-shield/generators/shields_io.rb', line 19

def generate
  return @image ||= begin
    generate!
  end
end