class Faker::Color

Public Class Methods

color_name() click to toggle source

Produces the name of a color.

@return [String]

@example

Faker::Color.color_name #=> "yellow"

@faker.version 1.6.2

# File lib/faker/default/color.rb, line 28
def color_name
  fetch('color.name')
end
hex_color() click to toggle source

Produces a hex color code.

@return [String]

@example

Faker::Color.hex_color #=> "#31a785"

@faker.version 1.5.0

# File lib/faker/default/color.rb, line 15
def hex_color
  format('#%06x', (rand * 0xffffff))
end
hsl_color() click to toggle source

Produces an array of floats representing an HSL color. The array is in the form of `[hue, saturation, lightness]`.

@return [Array(Float, Float, Float)]

@example

Faker::Color.hsl_color #=> [69.87, 0.66, 0.3]

@faker.version 1.5.0

# File lib/faker/default/color.rb, line 60
def hsl_color
  [sample((0..360).to_a), rand.round(2), rand.round(2)]
end
hsla_color() click to toggle source

Produces an array of floats representing an HSLA color. The array is in the form of `[hue, saturation, lightness, alpha]`.

@return [Array(Float, Float, Float, Float)]

@example

Faker::Color.hsla_color #=> [154.77, 0.36, 0.9, 0.2]

@faker.version 1.5.0

# File lib/faker/default/color.rb, line 74
def hsla_color
  hsl_color << rand.round(1)
end
rgb_color() click to toggle source

Produces an array of integers representing an RGB color.

@return [Array(Integer, Integer, Integer)]

@example

Faker::Color.rgb_color #=> [54, 233, 67]

@faker.version 1.5.0

# File lib/faker/default/color.rb, line 46
def rgb_color
  Array.new(3) { single_rgb_color }
end
single_rgb_color() click to toggle source

@private

# File lib/faker/default/color.rb, line 33
def single_rgb_color
  sample((0..255).to_a)
end