Class: AvatarOMatic::Generator
- Inherits:
-
Object
- Object
- AvatarOMatic::Generator
- Defined in:
- lib/avatar_o_matic/generator.rb
Instance Attribute Summary collapse
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #generate! ⇒ Object
-
#initialize(opts = {}) ⇒ Generator
constructor
A new instance of Generator.
- #save(path) ⇒ Object
- #type ⇒ Object
- #type=(type) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Generator
Returns a new instance of Generator.
19 20 21 22 23 24 25 26 27 |
# 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 |
Instance Attribute Details
#image ⇒ Object (readonly)
Returns the value of attribute image.
17 18 19 |
# File 'lib/avatar_o_matic/generator.rb', line 17 def image @image end |
#size ⇒ Object
Returns the value of attribute size.
16 17 18 |
# File 'lib/avatar_o_matic/generator.rb', line 16 def size @size end |
Instance Method Details
#generate! ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# 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| = MiniMagick::Image.open path_for prop @image = @image.composite() do |c| c.compose 'Over' end end @image.resize size if image.width != size self end |
#save(path) ⇒ Object
79 80 81 82 83 |
# File 'lib/avatar_o_matic/generator.rb', line 79 def save(path) raise NoImageYetError.new if @image.nil? @image.write path path end |
#type ⇒ Object
36 37 38 |
# File 'lib/avatar_o_matic/generator.rb', line 36 def type @type ||= Config.types.sample end |
#type=(type) ⇒ Object
29 30 31 32 33 34 |
# 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 |