Class: Systems::GithubShield
- Inherits:
-
Object
- Object
- Systems::GithubShield
- Defined in:
- lib/lingohub_shield/systems/github_shield.rb
Instance Method Summary collapse
-
#generate ⇒ Object
Generates the shield with previously initialized parameters.
-
#initialize(output_path, name, locales) ⇒ GithubShield
constructor
Initializes the github shield.
Constructor Details
#initialize(output_path, name, locales) ⇒ GithubShield
Initializes the github shield
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lingohub_shield/systems/github_shield.rb', line 10 def initialize(output_path, name, locales) @name = name @output_path = output_path # number of pixels from both ends of the label to the edge of the container @padding = 18 # width of the left and right strip that contains the rounded edges @corner_width = 2 lh_entry = Entry.new('LH', nil, @padding) @entries = [lh_entry] @shield_height = 25 @shield_width = lh_entry.width @label_keys = [:lh] locales.each do |locale| entry = Entry.new(locale[:iso_code], locale[:percentage], @padding) @entries << entry @shield_width += entry.width end @label_keys[1..-1].sort! @shield_width += @corner_width*2 @canvas = Magick::Image.new(@shield_width, @shield_height) { self.background_color = 'transparent' } @canvas.alpha(Magick::ActivateAlphaChannel) @draw = Magick::Draw.new end |
Instance Method Details
#generate ⇒ Object
Generates the shield with previously initialized parameters
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lingohub_shield/systems/github_shield.rb', line 44 def generate draw_right_corners(@entries.last) unless @entries.empty? draw_left_corners(@entries.first) offset = @corner_width @entries.each do |entry| draw_rectangle entry, offset draw_label entry, offset offset += entry.width end publish end |