Method: Faker::Color.hex_color

Defined in:
lib/faker/default/color.rb

.hex_color(args = nil) ⇒ String

Produces a hex color code. Clients are able to specify the hue, saturation, or lightness of the required color. Alternatively a client can simply specify that they need a light or dark color.

Examples:

Faker::Color.hex_color #=> "#31a785"
Faker::Color.hex_color(hue: 118, saturation: 1, lightness: 0.53) #=> "#048700"
Faker::Color.hex_color(:light) #=> "#FFEE99"
Faker::Color.hex_color(:dark) #=> "#665500"


29
30
31
32
33
34
# File 'lib/faker/default/color.rb', line 29

def hex_color(args = nil)
  hsl_hash = {}
  hsl_hash = { lightness: LIGHTNESS_LOOKUP[args] } if i[dark light].include?(args)
  hsl_hash = args if args.is_a?(Hash)
  hsl_to_hex(hsl_color(**hsl_hash))
end