Class: Avatari::Avatar

Inherits:
Object
  • Object
show all
Defined in:
lib/avatari/avatar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initials_method = nil, options = {}) ⇒ Avatar

Returns a new instance of Avatar.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/avatari/avatar.rb', line 11

def initialize initials_method = nil, options = {}
    defaults = {
        colors: ['#000000'],
        versions: {
            mini: [40,40],
            tiny: [50,50],
            small: [75,75],
            medium: [100,100],
            big: [350,350],
            raw: [800,800]
        },
        default_version: nil,
        process: [800,800],
        extension_whitelist: ['jpg','jpeg','png']
    }
    options = defaults.merge! options

    @initials_method = initials_method
    @colors = options[:colors]
    @versions = options[:versions]
    @default_version = options[:default_version]
    @process = options[:process]
    @extension_whitelist = options[:extension_whitelist]
end

Instance Attribute Details

#colorsObject

Returns the value of attribute colors.



5
6
7
# File 'lib/avatari/avatar.rb', line 5

def colors
  @colors
end

#default_versionObject

Returns the value of attribute default_version.



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

def default_version
  @default_version
end

#extension_whitelistObject

Returns the value of attribute extension_whitelist.



9
10
11
# File 'lib/avatari/avatar.rb', line 9

def extension_whitelist
  @extension_whitelist
end

#initials_methodObject

Returns the value of attribute initials_method.



4
5
6
# File 'lib/avatari/avatar.rb', line 4

def initials_method
  @initials_method
end

#processObject

Returns the value of attribute process.



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

def process
  @process
end

#versionsObject

Returns the value of attribute versions.



6
7
8
# File 'lib/avatari/avatar.rb', line 6

def versions
  @versions
end

Instance Method Details

#initials(object) ⇒ Object



36
37
38
39
40
# File 'lib/avatari/avatar.rb', line 36

def initials object
    raw = object.send(self.initials_method)
    r = ''; raw.nil? ? nil : raw.split(' ').first(2).each { |n| r += n[0].upcase }
    return r
end