Sha256: b866b909bb49221dbff3d045ec474429f60c87c8d57f7e60fff2fe0dc3e5c64c

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module Thinreports
  module Generator
    class PDF
      module ParseColor
        # @param [String] color
        # @return [String]
        def parse_color(color)
          color = color.downcase

          if color =~ /^#?[\da-f]{6}$/
            color.delete('#')
          else
            find_color_from_name(color)
          end
        end

        private

        # Supported only SAFE COLORS.
        SUPPORTED_COLOR_NAMES = {
          'red'     => 'ff0000',
          'yellow'  => 'fff000',
          'lime'    => '00ff00',
          'aqua'    => '00ffff',
          'blue'    => '0000ff',
          'fuchsia' => 'ff00ff',
          'maroon'  => '800000',
          'olive'   => '808000',
          'green'   => '008800',
          'teal'    => '008080',
          'navy'    => '000080',
          'purple'  => '800080',
          'black'   => '000000',
          'gray'    => '808080',
          'silver'  => 'c0c0c0',
          'white'   => 'ffffff'
        }.freeze

        def find_color_from_name(name)
          color = SUPPORTED_COLOR_NAMES[name]
          raise Thinreports::Errors::UnsupportedColorName, name unless color
          color
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
thinreports-0.12.1 lib/thinreports/generator/pdf/document/parse_color.rb
thinreports-0.12.0 lib/thinreports/generator/pdf/document/parse_color.rb
thinreports-0.11.0 lib/thinreports/generator/pdf/document/parse_color.rb
thinreports-0.10.3 lib/thinreports/generator/pdf/document/parse_color.rb
thinreports-0.10.2 lib/thinreports/generator/pdf/document/parse_color.rb
thinreports-0.10.1 lib/thinreports/generator/pdf/document/parse_color.rb
thinreports-0.10.0 lib/thinreports/generator/pdf/document/parse_color.rb