Class: Pixitar::Avatar
- Inherits:
-
Object
- Object
- Pixitar::Avatar
- Defined in:
- lib/pixitar.rb
Defined Under Namespace
Classes: InvalidGenderError, MissingImageFilesError
Instance Attribute Summary collapse
-
#assets_path ⇒ Object
readonly
Returns the value of attribute assets_path.
-
#gender ⇒ Object
readonly
Returns the value of attribute gender.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#image_extention ⇒ Object
readonly
Returns the value of attribute image_extention.
Instance Method Summary collapse
- #face_parts ⇒ Object
- #female_avatar ⇒ Object
- #genders ⇒ Object
- #generate_avatar(gender = random_gender, filename = "avatar.png") ⇒ Object
-
#initialize(image_klass = Pixitar::Image.new, opts = {}) ⇒ Avatar
constructor
A new instance of Avatar.
- #male_avatar ⇒ Object
- #random_gender ⇒ Object
Constructor Details
#initialize(image_klass = Pixitar::Image.new, opts = {}) ⇒ Avatar
Returns a new instance of Avatar.
33 34 35 36 37 |
# File 'lib/pixitar.rb', line 33 def initialize(image_klass = Pixitar::Image.new, opts = {}) @image = image_klass @assets_path = opts.fetch(:assets_path, "images") @image_extention = opts.fetch(:image_extention, "png") end |
Instance Attribute Details
#assets_path ⇒ Object (readonly)
Returns the value of attribute assets_path.
29 30 31 |
# File 'lib/pixitar.rb', line 29 def assets_path @assets_path end |
#gender ⇒ Object (readonly)
Returns the value of attribute gender.
31 32 33 |
# File 'lib/pixitar.rb', line 31 def gender @gender end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
28 29 30 |
# File 'lib/pixitar.rb', line 28 def image @image end |
#image_extention ⇒ Object (readonly)
Returns the value of attribute image_extention.
30 31 32 |
# File 'lib/pixitar.rb', line 30 def image_extention @image_extention end |
Instance Method Details
#face_parts ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pixitar.rb', line 39 def face_parts [ :background, :clothes, :face, :hair, :mouth, :eye ] end |
#female_avatar ⇒ Object
65 66 67 |
# File 'lib/pixitar.rb', line 65 def female_avatar generate_avatar(:female) end |
#genders ⇒ Object
50 51 52 53 54 55 |
# File 'lib/pixitar.rb', line 50 def genders [ :male, :female ] end |
#generate_avatar(gender = random_gender, filename = "avatar.png") ⇒ Object
69 70 71 72 73 74 |
# File 'lib/pixitar.rb', line 69 def generate_avatar(gender = random_gender, filename = "avatar.png") @gender = gender raise InvalidGenderError unless genders.include?(gender) create_avatar_image(filename) end |
#male_avatar ⇒ Object
61 62 63 |
# File 'lib/pixitar.rb', line 61 def male_avatar generate_avatar(:male) end |
#random_gender ⇒ Object
57 58 59 |
# File 'lib/pixitar.rb', line 57 def random_gender genders.sample end |