Class: Faker::Color
Constant Summary
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.color_name ⇒ String
Produces the name of a color.
-
.hex_color ⇒ String
Produces a hex color code.
-
.hsl_color ⇒ Array(Float, Float, Float)
Produces an array of floats representing an HSL color.
-
.hsla_color ⇒ Array(Float, Float, Float, Float)
Produces an array of floats representing an HSLA color.
-
.rgb_color ⇒ Array(Integer, Integer, Integer)
Produces an array of integers representing an RGB color.
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_name ⇒ String
Produces the name of a color.
28 29 30 |
# File 'lib/faker/default/color.rb', line 28 def color_name fetch('color.name') end |
.hex_color ⇒ String
Produces a hex color code.
15 16 17 |
# File 'lib/faker/default/color.rb', line 15 def hex_color format('#%06x', (rand * 0xffffff)) end |
.hsl_color ⇒ Array(Float, Float, Float)
Produces an array of floats representing an HSL color. The array is in the form of `[hue, saturation, lightness]`.
60 61 62 |
# 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 ⇒ Array(Float, Float, Float, Float)
Produces an array of floats representing an HSLA color. The array is in the form of `[hue, saturation, lightness, alpha]`.
74 75 76 |
# File 'lib/faker/default/color.rb', line 74 def hsla_color hsl_color << rand.round(1) end |
.rgb_color ⇒ Array(Integer, Integer, Integer)
Produces an array of integers representing an RGB color.
46 47 48 |
# File 'lib/faker/default/color.rb', line 46 def rgb_color Array.new(3) { single_rgb_color } end |