Class: Gamercard

Inherits:
Object
  • Object
show all
Includes:
Magick
Defined in:
lib/template.rb,
lib/gamercard.rb,
lib/templater.rb

Overview

Gamercard.new.generate({:name => ‘basic’, :player => ‘mattetti’)

Defined Under Namespace

Classes: Template, Templater

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_data) ⇒ Gamercard

Returns a new instance of Gamercard.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gamercard.rb', line 12

def initialize(template_data)
  unless template_data.respond_to?(:has_key?) && template_data.has_key?('name')
    raise Template::OptionError, 'make sure your template info has a name key and that the key is a string'
  end
  @templater = Templater.new(template_data)
  
  # @columns      = 600.0
  # @rows         = 100.0
  # @font_color   = 'white'
  # @font         = File.expand_path(File.join(File.dirname(__FILE__), 'fonts', 'Vera.ttf'))
  # @margin       = 10.0
  # @avatar_width = (@rows - @margin)
  # @avatar_x     = (@columns - (@avatar_width + (@margin/2)))
  # @avatar_y     = ((@rows - @avatar_width)/2)

end

Instance Attribute Details

#templaterObject

Returns the value of attribute templater.



10
11
12
# File 'lib/gamercard.rb', line 10

def templater
  @templater
end

Instance Method Details

#generate(username, stats = {}) ⇒ Object



34
35
36
# File 'lib/gamercard.rb', line 34

def generate(username, stats={})
  template.generate(username, stats)
end

#insert_avatar(avatar_file = nil) ⇒ Object

def generate(username)

@username = username
@base = render_gradiated_background
insert_avatar
label
last_game
stats
insert_url
@base.write("#{username}.png")

end



57
58
59
60
61
62
63
# File 'lib/gamercard.rb', line 57

def insert_avatar(avatar_file=nil)
  if avatar_file
    @avatar        = Image.read('avatar.jpg')[0]
    resized_avatar = @avatar.resize_to_fit(@avatar_width, @avatar_width)
    @base.composite!(resized_avatar, @avatar_x, @avatar_y, OverCompositeOp)
  end
end

#insert_urlObject



95
96
97
98
99
100
101
102
103
# File 'lib/gamercard.rb', line 95

def insert_url
  @d.fill      = @font_color
  @d.font      = @font
  @d.pointsize = 8.0
  @d.stroke('transparent')
  @d.font_weight = NormalWeight
  @d.gravity     = WestGravity
  @d             = @d.annotate_scaled(@base, @columns, 1.0, @margin, (@rows - @margin), "http://theshowcommunity.com/players/#{@username}", 1)    
end

#labelObject



65
66
67
68
69
70
71
72
73
# File 'lib/gamercard.rb', line 65

def label
  @d.fill        = @font_color
  @d.font        = @font
  @d.pointsize   = 14.0
  @d.stroke('transparent')
  @d.font_weight = NormalWeight
  @d.gravity     = WestGravity
  @d             = @d.annotate_scaled(@base, @columns, 1.0, @margin, @margin, "MLB10 #{@username}", 1)
end

#last_gameObject



75
76
77
78
79
80
81
82
83
# File 'lib/gamercard.rb', line 75

def last_game
  @d.fill        = @font_color
  @d.font        = @font
  @d.pointsize   = 8.0
  @d.stroke('transparent')
  @d.font_weight = NormalWeight
  @d.gravity     = WestGravity
  @d             = @d.annotate_scaled(@base, @columns, 1.0, @margin, (@rows/4), "Last Game: #{Time.now.to_s}", 1)
end

#render_gradiated_background(top_color = '#4a465a', bottom_color = 'black') ⇒ Object

Use with a theme definition method to draw a gradiated background.



106
107
108
# File 'lib/gamercard.rb', line 106

def render_gradiated_background(top_color='#4a465a', bottom_color='black')
  Image.new(@columns, @rows, GradientFill.new(0, 0, 100, 0, top_color, bottom_color))
end

#save(path = nil) ⇒ Object



38
39
40
# File 'lib/gamercard.rb', line 38

def save(path=nil)
  template.save
end

#statsObject



85
86
87
88
89
90
91
92
93
# File 'lib/gamercard.rb', line 85

def stats
  @d.fill        = @font_color
  @d.font        = @font
  @d.pointsize   = 8.0
  @d.stroke('transparent')
  @d.font_weight = NormalWeight
  @d.gravity     = WestGravity
  @d             = @d.annotate_scaled(@base, @columns, 1.0, @margin, ((@rows/4)*2), "Stats: 1 | 2 | 3 | 4 | 5 | 6 |\nmore stats on this line", 1)
end

#templateObject

Returns the template object via the templater



30
31
32
# File 'lib/gamercard.rb', line 30

def template
  templater.template
end

#to_ioObject



42
43
44
# File 'lib/gamercard.rb', line 42

def to_io
  template.to_io
end