Class: Faker::Color

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

Constant Summary

Constants inherited from Base

Base::Letters, 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

.color_nameObject


10
11
12
# File 'lib/faker/default/color.rb', line 10

def color_name
  fetch('color.name')
end

.hex_colorObject


6
7
8
# File 'lib/faker/default/color.rb', line 6

def hex_color
  format('#%06x', (rand * 0xffffff))
end

.hsl_colorObject

returns [hue, saturation, lightness]


23
24
25
# File 'lib/faker/default/color.rb', line 23

def hsl_color
  [sample((0..360).to_a), rand.round(2), rand.round(2)]
end

.hsla_colorObject


27
28
29
# File 'lib/faker/default/color.rb', line 27

def hsla_color
  hsl_color << rand.round(1)
end

.rgb_colorObject


18
19
20
# File 'lib/faker/default/color.rb', line 18

def rgb_color
  Array.new(3) { single_rgb_color }
end

.single_rgb_colorObject


14
15
16
# File 'lib/faker/default/color.rb', line 14

def single_rgb_color
  sample((0..255).to_a)
end