Sha256: 320b05cbdb247ee7f76e158526062b037dda70b7387c8c62cc0d9d00c8ae6c8c

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

# encoding: utf-8

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
      "#{random_rgb_value},#{random_rgb_value},#{random_rgb_value}"
    end

    def rgba_array
      [random_rgb_value, random_rgb_value, random_rgb_value, random_opacity_value]
    end

    def rgba_list
      "#{random_rgb_value},#{random_rgb_value},#{random_rgb_value},#{random_opacity_value}"
    end

    def hsl_array
      [random_hue_value, random_percentage_string, random_percentage_string]
    end

    def hsl_list
      "#{random_hue_value},#{random_percentage_string},#{random_percentage_string}"
    end

    def hsla_array
      [random_hue_value, random_percentage_string, random_percentage_string, random_opacity_value]
    end

    def hsla_list
      "#{random_hue_value},#{random_percentage_string},#{random_percentage_string},#{random_opacity_value}"
    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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ffaker-2.11.0 lib/ffaker/color.rb
ffaker-2.10.0 lib/ffaker/color.rb
ffaker-2.9.0 lib/ffaker/color.rb
ffaker-2.8.1 lib/ffaker/color.rb
ffaker-2.8.0 lib/ffaker/color.rb
ffaker-2.7.0 lib/ffaker/color.rb