Sha256: 45e5153bbec5bba4126d82ea8964d4fadda5ae176b35d32ffcf04ce81abc7949
Contents?: true
Size: 1.02 KB
Versions: 13
Compression:
Stored size: 1.02 KB
Contents
module Faker class Placeholdit < Base class << self SUPPORTED_FORMATS = %w(png jpg gif jpeg) def image(size = '300x300', format = 'png', background_color = nil, text_color = nil, text = nil) 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) raise ArgumentError, "background_color must be a hex value without '#'" unless background_color.nil? || background_color.match(/((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/) raise ArgumentError, "text_color must be a hex value without '#'" unless text_color.nil? || text_color.match(/((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/) image_url = "https://placehold.it/#{size}.#{format}" image_url += "/#{background_color}" if background_color image_url += "/#{text_color}" if text_color image_url += "?text=#{text}" if text image_url end end end end
Version data entries
13 entries across 13 versions & 1 rubygems