File: color.rb

package info (click to toggle)
ruby-ffaker 2.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,776 kB
  • sloc: ruby: 12,788; makefile: 8; sh: 1
file content (66 lines) | stat: -rw-r--r-- 1,015 bytes parent folder | download | duplicates (3)
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
# frozen_string_literal: true

module FFaker
  module Color
    extend ModuleUtils
    extend self

    def name
      fetch_sample(NAMES_LIST)
    end

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

    def rgb_array
      [random_rgb_value, random_rgb_value, random_rgb_value]
    end

    def rgb_list
      rgb_array.join(',')
    end

    def rgba_array
      rgb_array << random_opacity_value
    end

    def rgba_list
      rgba_array.join(',')
    end

    def hsl_array
      [random_hue_value, random_percentage_string, random_percentage_string]
    end

    def hsl_list
      hsl_array.join(',')
    end

    def hsla_array
      hsl_array << random_opacity_value
    end

    def hsla_list
      hsla_array.join(',')
    end

    private

    def random_rgb_value
      rand 255
    end

    def random_opacity_value
      rand(0.0..1.0).round(2)
    end

    def random_hue_value
      rand(0..359)
    end

    def random_percentage_string
      "#{rand(0..99)}%"
    end
  end
end