Module: FFaker::Avatar

Extended by:
Avatar, ModuleUtils
Included in:
Avatar
Defined in:
lib/ffaker/avatar.rb

Constant Summary collapse

SUPPORTED_FORMATS =
%w(png jpg bmp)

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, underscore

Instance Method Details

#image(slug = nil, size = '300x300', format = 'png', bgset = nil) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/ffaker/avatar.rb', line 10

def image(slug = nil, size = '300x300', format = 'png', bgset = nil)
  fail ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/
  fail ArgumentError, "Supported formats are #{SUPPORTED_FORMATS.join(', ')}" unless SUPPORTED_FORMATS.include?(format)
  fail ArgumentError, 'Not a supported background number. Choose eather 1 or 2' unless bgset.nil? || (1..2).cover?(bgset.to_i)
  slug ||= FFaker::Lorem.words.join
  "https://robohash.org/#{slug}.#{format}?size=#{size}#{'&bgset=bg' + bgset.to_s unless bgset.nil?}"
end