Class: Faker::Color

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

Constant Summary

Constants inherited from Base

Base::Letters, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

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

Class Method Details

.color_nameObject



8
9
10
# File 'lib/faker/color.rb', line 8

def color_name
  fetch('color.name')
end

.hex_colorObject



4
5
6
# File 'lib/faker/color.rb', line 4

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

.hsl_colorObject

returns [hue, saturation, lightness]



21
22
23
# File 'lib/faker/color.rb', line 21

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

.hsla_colorObject



25
26
27
# File 'lib/faker/color.rb', line 25

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

.rgb_colorObject



16
17
18
# File 'lib/faker/color.rb', line 16

def rgb_color
  3.times.collect { single_rgb_color }
end

.single_rgb_colorObject



12
13
14
# File 'lib/faker/color.rb', line 12

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