Class: PlaceKitten

Inherits:
Object
  • Object
show all
Defined in:
lib/placekitten/placekitten.rb

Defined Under Namespace

Modules: Helpers

Constant Summary collapse

DEFAULT_WIDTH =
300
DEFAULT_HEIGHT =
300

Class Method Summary collapse

Class Method Details

.grayscale(width = nil, height = nil) ⇒ Object Also known as: gray

Returns the URL for a grayscale placekitten with the given width and height. If the width is given but the height is not, the image will be square.

Parameters:

  • width (Number) (defaults to: nil)

    the width of the placekitten

  • height (Number) (defaults to: nil)

    the height of the placekitten



33
34
35
# File 'lib/placekitten/placekitten.rb', line 33

def self.grayscale(width = nil, height = nil)
  self.image(width, height, true)
end

.image(width = nil, height = nil, grayscale = false) ⇒ Object Also known as: kitten

Returns the URL for an optionally grayscale placekitten with the given width and height. If the width is given but the height is not, the image will be square.

Parameters:

  • width (Number) (defaults to: nil)

    the width of the placekitten

  • height (Number) (defaults to: nil)

    the height of the placekitten

  • grayscale (Boolean) (defaults to: false)

    whether or not to make the placekitten grayscale



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/placekitten/placekitten.rb', line 12

def self.image(width = nil, height = nil, grayscale = false)
  if width.nil?
    width = DEFAULT_WIDTH
    height = DEFAULT_HEIGHT
  elsif height.nil?
    height = width
  end

  if grayscale
    "http://placekitten.com/g/#{width}/#{height}"
  else
    "http://placekitten.com/#{width}/#{height}"
  end
end