Class: Faker::Fillmurray

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

Constant Summary

Constants inherited from Base

Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale

Class Method Details

.image(legacy_grayscale = NOT_GIVEN, legacy_width = NOT_GIVEN, legacy_height = NOT_GIVEN, grayscale: false, width: 200, height: 200) ⇒ String

Produces the URL of an image from Fill Murray, a site which hosts exclusively photographs of actor Bill Murray.

Examples:

Faker::Fillmurray.image #=> "https://www.fillmurray.com/300/300"
Faker::Fillmurray.image(grayscale: true)
  #=> "https://fillmurray.com/g/300/300"
Faker::Fillmurray.image(grayscale: false, width: 200, height: 400)
  #=> "https://fillmurray.com/200/400"

Parameters:

  • grayscale (Boolean) (defaults to: false)

    Whether to return a grayscale image.

  • width (Integer) (defaults to: 200)

    The iamage width.

  • height (Integer) (defaults to: 200)

    The image height.

Returns:

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/faker/default/fillmurray.rb', line 29

def image(legacy_grayscale = NOT_GIVEN, legacy_width = NOT_GIVEN, legacy_height = NOT_GIVEN, grayscale: false, width: 200, height: 200)
  warn_for_deprecated_arguments do |keywords|
    keywords << :grayscale if legacy_grayscale != NOT_GIVEN
    keywords << :width if legacy_width != NOT_GIVEN
    keywords << :height if legacy_height != NOT_GIVEN
  end

  raise ArgumentError, 'Width should be a number' unless width.to_s =~ /^\d+$/
  raise ArgumentError, 'Height should be a number' unless height.to_s =~ /^\d+$/
  raise ArgumentError, 'Grayscale should be a boolean' unless [true, false].include?(grayscale)

  "https://www.fillmurray.com#{'/g' if grayscale == true}/#{width}/#{height}"
end