Class: Faker::Avatar

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

Constant Summary

SUPPORTED_FORMATS =
%w(png jpg bmp)

Constants inherited from Base

Base::Letters, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, fetch, flexible, letterify, method_missing, numerify, parse, rand_in_range, regexify, translate

Class Method Details

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

Raises:

  • (ArgumentError)


6
7
8
9
10
11
# File 'lib/faker/avatar.rb', line 6

def image(slug = nil, size = '300x300', format = 'png')
  raise ArgumentError, "Size should be specified in format 300x300" unless size.match(/^[0-9]+x[0-9]+$/)
  raise ArgumentError, "Supported formats are #{SUPPORTED_FORMATS.join(', ')}" unless SUPPORTED_FORMATS.include?(format)
  slug ||= Faker::Lorem.words.join
  "http://robohash.org/#{slug}.#{format}?size=#{size}"
end