class RingCentral::Avatars::MultiAvatar
Constants
- AVATARLY_DEFAULTS
- DEFAULT_STYLE
- IDENTICON_DEFAULTS
- IDENTICON_DEFAULT_FORMAT
Public Class Methods
new(opts = {})
click to toggle source
# File lib/ringcentral-avatars/creator.rb, line 162 def initialize(opts = {}) @avatarly_opts = inflate_avatarly_opts opts[:initials_opts] @identicon_opts = inflate_identicon_opts opts[:identicon_opts] @style = opts.key?(:style) ? opts[:style] : DEFAULT_STYLE @png_metadata = opts.key?(:png_metadata) ? opts[:png_metadata] : {} @logger = opts.key?(:logger) ? opts[:logger] : Logger.new(STDOUT) end
Public Instance Methods
avatar_blob(text, style = nil)
click to toggle source
# File lib/ringcentral-avatars/creator.rb, line 180 def avatar_blob(text, style = nil) style = @style if style.nil? blob = style == 'initials' \ ? Avatarly.generate_avatar(text, @avatarly_opts) \ : RubyIdenticon.create(text, @identicon_opts) inflate_avatar_blob_png blob end
avatar_extension()
click to toggle source
# File lib/ringcentral-avatars/creator.rb, line 222 def avatar_extension ".#{avatar_format}" end
avatar_faraday_uploadio(text, style = nil)
click to toggle source
# File lib/ringcentral-avatars/creator.rb, line 204 def avatar_faraday_uploadio(text, style = nil) file = avatar_temp_file text, style @logger.debug "Building Avatar Temp File: #{file.path}" Faraday::UploadIO.new file.path, avatar_mime_type end
avatar_format()
click to toggle source
# File lib/ringcentral-avatars/creator.rb, line 210 def avatar_format @style == 'initials' ? @avatarly_opts[:format] : IDENTICON_DEFAULT_FORMAT end
avatar_mime_type()
click to toggle source
# File lib/ringcentral-avatars/creator.rb, line 214 def avatar_mime_type types = MIME::Types.type_for avatar_format if types.empty? raise "Unknown avatar format: #{avatar_format}" end types[0].to_s end
avatar_temp_file(text, style = nil)
click to toggle source
# File lib/ringcentral-avatars/creator.rb, line 195 def avatar_temp_file(text, style = nil) blob = avatar_blob text, style file = Tempfile.new ['avatar', avatar_extension] file.binmode file.write blob file.flush file end
inflate_avatar_blob_png(blob)
click to toggle source
# File lib/ringcentral-avatars/creator.rb, line 188 def inflate_avatar_blob_png(blob) return blob unless avatar_format == 'png' && @png_metadata img = ChunkyPNG::Image.from_blob blob img.metadata = @png_metadata img.to_blob end
inflate_avatarly_opts(avatarly_opts = {})
click to toggle source
# File lib/ringcentral-avatars/creator.rb, line 170 def inflate_avatarly_opts(avatarly_opts = {}) avatarly_opts = {} unless avatarly_opts.is_a? Hash AVATARLY_DEFAULTS.merge avatarly_opts end
inflate_identicon_opts(identicon_opts = {})
click to toggle source
# File lib/ringcentral-avatars/creator.rb, line 175 def inflate_identicon_opts(identicon_opts = {}) identicon_opts = {} unless identicon_opts.is_a? Hash IDENTICON_DEFAULTS.merge identicon_opts end