Repository navigation
Expand file tree
/
Copy pathcolor.rb
More file actions
79 lines (73 loc) · 1.77 KB
/
Copy pathcolor.rb
File metadata and controls
79 lines (73 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# frozen_string_literal: true
module Faker
class Color < Base
class << self
##
# Produces a hex color code.
#
# @return [String]
#
# @example
# Faker::Color.hex_color #=> "#31a785"
#
# @faker.version 1.5.0
def hex_color
format('#%06x', (rand * 0xffffff))
end
##
# Produces the name of a color.
#
# @return [String]
#
# @example
# Faker::Color.color_name #=> "yellow"
#
# @faker.version 1.6.2
def color_name
fetch('color.name')
end
# @private
def single_rgb_color
sample((0..255).to_a)
end
##
# 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
def rgb_color
Array.new(3) { single_rgb_color }
end
##
# 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
def hsl_color
[sample((0..360).to_a), rand.round(2), rand.round(2)]
end
##
# 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
def hsla_color
hsl_color << rand.round(1)
end
end
end
end