Class: Pixitar::Avatar
- Inherits:
-
Object
show all
- Defined in:
- lib/pixitar.rb
Defined Under Namespace
Classes: InvalidGenderError, MissingImageFilesError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(image_klass = Pixitar::Image.new, opts = {}) ⇒ 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
Returns the value of attribute assets_path.
29
30
31
|
# File 'lib/pixitar.rb', line 29
def assets_path
@assets_path
end
|
#gender ⇒ Object
Returns the value of attribute gender.
31
32
33
|
# File 'lib/pixitar.rb', line 31
def gender
@gender
end
|
#image ⇒ Object
Returns the value of attribute image.
28
29
30
|
# File 'lib/pixitar.rb', line 28
def image
@image
end
|
#image_extention ⇒ Object
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
|