Class: Gamercard::Template

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

Direct Known Subclasses

Basic

Defined Under Namespace

Classes: OptionError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Template

Returns a new instance of Template.



10
11
12
13
14
# File 'lib/template.rb', line 10

def initialize(settings={})
  @passed_settings = settings
  @generated = false
  process_settings(settings) if self.class.method_defined?(:process_settings)
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



8
9
10
# File 'lib/template.rb', line 8

def base
  @base
end

#filenameObject (readonly)

Returns the value of attribute filename.



8
9
10
# File 'lib/template.rb', line 8

def filename
  @filename
end

#generatedObject (readonly)

Returns the value of attribute generated.



8
9
10
# File 'lib/template.rb', line 8

def generated
  @generated
end

#heightObject (readonly)

Returns the value of attribute height.



8
9
10
# File 'lib/template.rb', line 8

def height
  @height
end

#passed_settingsObject (readonly)

Returns the value of attribute passed_settings.



7
8
9
# File 'lib/template.rb', line 7

def passed_settings
  @passed_settings
end

#statsObject (readonly)

Returns the value of attribute stats.



8
9
10
# File 'lib/template.rb', line 8

def stats
  @stats
end

#usernameObject (readonly)

Returns the value of attribute username.



8
9
10
# File 'lib/template.rb', line 8

def username
  @username
end

#widthObject (readonly)

Returns the value of attribute width.



8
9
10
# File 'lib/template.rb', line 8

def width
  @width
end

Class Method Details

.fonts_pathObject



16
17
18
# File 'lib/template.rb', line 16

def self.fonts_path
  File.expand_path(File.join(File.dirname(__FILE__), 'fonts'))
end

Instance Method Details

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



35
36
37
# File 'lib/template.rb', line 35

def gradient_background(top_color='#4a465a', bottom_color='black')
  Image.new(width, height, GradientFill.new(0, 0, width, 0, top_color, bottom_color))
end

#save(path = nil) ⇒ Object

template helpers inherited by all templates



22
23
24
25
# File 'lib/template.rb', line 22

def save(path=nil)
  file_path = path.nil? ? (filename || 'image.png') : File.join(path, (filename || 'image.png'))
  base.write(file_path)
end

#to_ioObject



27
28
29
30
31
32
33
# File 'lib/template.rb', line 27

def to_io
  if @generated
    StringIO.new(base.to_blob{ self.format = 'PNG' })
  else
    nil
  end
end