class AvatarOMatic::Generator
Attributes
image[R]
size[RW]
Public Class Methods
new(opts={})
click to toggle source
Calls superclass method
# File lib/avatar_o_matic/generator.rb, line 19 def initialize(opts={}) super() opts.keys.select {|k| (Config.properties + [:size]).include? k }.each do |opt| self.send :"#{opt}=", opts[opt] end @size ||= 400 end
Public Instance Methods
generate!()
click to toggle source
# File lib/avatar_o_matic/generator.rb, line 64 def generate! @image = MiniMagick::Image.open path_for :background Config.properties.select {|p| p != :background }.each do |prop| overlay = MiniMagick::Image.open path_for prop @image = @image.composite(overlay) do |c| c.compose 'Over' end end @image.resize size if image.width != size self end
save(path)
click to toggle source
# File lib/avatar_o_matic/generator.rb, line 79 def save(path) raise NoImageYetError.new if @image.nil? @image.write path path end
type()
click to toggle source
# File lib/avatar_o_matic/generator.rb, line 36 def type @type ||= Config.types.sample end
type=(type)
click to toggle source
# File lib/avatar_o_matic/generator.rb, line 29 def type=(type) unless Config.types.include? type.to_sym raise InvalidPropertyError.new("#{type} is not a recognised type") end @type = type end
Private Instance Methods
option(prop)
click to toggle source
# File lib/avatar_o_matic/generator.rb, line 87 def option(prop) self.send prop.to_sym end
path_for(prop)
click to toggle source
# File lib/avatar_o_matic/generator.rb, line 91 def path_for(prop) Config.options_for(type, prop)[option prop] end