Class LaurelBuilder
In: lib/laurel_builder.rb
Parent: Object

For creating badges and medals.

Methods

Public Class methods

Creates the badge with ImageMagick

[Source]

    # File lib/laurel_builder.rb, line 19
19:   def self.build_badge(name, pg_name, percentile, at, helpers)
20:     percentile = self.round_percentile(percentile)
21:     category = helpers.percentile_category(percentile)
22:     if category > 1
23:       l_nr = ((category - 6) * -1).to_s
24:     else
25:       l_nr = '4'
26:     end
27:     img = Magick::Image.read("#{RAILS_ROOT}/public/images/badge" + 
28:         l_nr + ".png").first
29: 
30:     text = Magick::Draw.new
31: 
32:     text.font_family = 'verdana'
33: 
34:     text.annotate(img, 0, 0, 10, 5, helpers.truncate(name, 18,'..')) {
35:       self.pointsize = 10
36:       self.gravity = Magick::NorthWestGravity
37:     }
38:     text.annotate(img, 0,0,((category < 3 or category > 4) ? 52 : 
39:         (category != 3 ? 65 : 58)), -5, helpers.percentile_in_words(
40:             percentile)) {
41:       self.pointsize = (category != 2 ? 13 : 15)
42:       self.kerning = (category != 2 ? -0.7 : 0)
43:       self.gravity = Magick::WestGravity
44:     }
45:     text.annotate(img, 0, 0, 80, 8, at) {
46:       self.pointsize = 10
47:       self.kerning = 0
48:       self.gravity = Magick::WestGravity
49:     }
50:     text.annotate(img, 0,0,3,3, helpers.truncate(pg_name, 14, '..')) {
51:       self.pointsize = 10
52:       self.kerning = -0.5
53:       self.gravity = Magick::SouthEastGravity
54:     }
55:     new = Magick::Image.new(120, 60) {
56:       self.background_color = 'white'
57:     }
58:     text.annotate(new, 0, 0, 17, 26, percentile.to_s) {
59:       self.pointsize = 18
60:       self.kerning = 0
61:       self.gravity = Magick::NorthWestGravity
62:     }
63:     new = new.shade(true, 310, 70)
64:     new = new.matte_replace(0,0)
65:     img = img.composite(new, Magick::SouthWestGravity, 0, 0, 
66:         Magick::OverCompositeOp)
67:     return img
68:   end

Creates the medal with ImageMagick

[Source]

    # File lib/laurel_builder.rb, line 72
72:   def self.build_medal(percentile, helpers)
73:     percentile = self.round_percentile(percentile)
74:     category = helpers.percentile_category(percentile)
75:     if category > 1
76:       l_nr = ((category - 6) * -1).to_s
77:     else
78:       l_nr = '4'
79:     end
80:     img = Magick::Image.read("#{RAILS_ROOT}/public/images/medal" +
81:         l_nr + ".png").first
82: 
83:     text = Magick::Draw.new
84: 
85:     text.font_family = 'verdana'
86: 
87:     new = Magick::Image.new(90, 90) {
88:       self.background_color = 'white'
89:     }
90:     text.annotate(new, 0, 0, 31, 40, percentile.to_s) {
91:       self.pointsize = 26
92:       self.gravity = Magick::NorthWestGravity
93:     }
94:     new = new.shade(true, 310, 70)
95:     new = new.matte_replace(0,0)
96:     img = img.composite(new, Magick::SouthWestGravity, 0, 0,
97:         Magick::OverCompositeOp)
98:     return img
99:   end

[Source]

     # File lib/laurel_builder.rb, line 101
101:   def self.round_percentile(percentile)
102:     if percentile < 0 or percentile > 100
103:       raise 'Error, percentile out of bounds'
104:     end
105:     return percentile.round
106:   end

[Validate]