Sha256: 1a1138712f3da5d8197626b2698ad3a75a360506c94c23e7c27054c24ee7ce2d

Contents?: true

Size: 1017 Bytes

Versions: 9

Compression:

Stored size: 1017 Bytes

Contents

# frozen_string_literal: true

module FFakerTW
  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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ffakerTW-1.8.0 lib/ffakerTW/color.rb
ffakerTW-1.7.0 lib/ffakerTW/color.rb
ffakerTW-1.6.0 lib/ffakerTW/color.rb
ffakerTW-1.5.0 lib/ffakerTW/color.rb
ffakerTW-1.4.0 lib/ffakerTW/color.rb
ffakerTW-1.3.0 lib/ffakerTW/color.rb
ffakerTW-1.2.0 lib/ffakerTW/color.rb
ffakerTW-1.1.0 lib/ffakerTW/color.rb
ffakerTW-0.1.0 lib/ffakerTW/color.rb