Class: Faker::Avatar
Constant Summary collapse
- SUPPORTED_FORMATS =
%w[png jpg bmp].freeze
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.image(slug: nil, size: '300x300', format: 'png', set: 'set1', bgset: nil) ⇒ String
Produces a URL for an avatar from robohash.org.
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, shuffle!, translate, unique, with_locale
Class Method Details
.image(slug: nil, size: '300x300', format: 'png', set: 'set1', bgset: nil) ⇒ String
Produces a URL for an avatar from robohash.org
39 40 41 42 43 44 45 46 |
# File 'lib/faker/default/avatar.rb', line 39 def image(slug: nil, size: '300x300', format: 'png', set: 'set1', bgset: nil) raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/ raise ArgumentError, "Supported formats are #{SUPPORTED_FORMATS.join(', ')}" unless SUPPORTED_FORMATS.include?(format) slug ||= Faker::Lorem.words.join bgset_query = "&bgset=#{bgset}" if bgset "https://robohash.org/#{slug}.#{format}?size=#{size}&set=#{set}#{bgset_query}" end |