Class: CSVPlusPlus::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_plus_plus/color.rb

Overview

A color value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hex_string) ⇒ Color

create an instance from a string like “#FFF” or “#FFFFFF”



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/csv_plus_plus/color.rb', line 9

def initialize(hex_string)
  @red, @green, @blue =
    hex_string
    .gsub(/^#?/, '')
    .match(/(\w\w?)(\w\w?)(\w\w?)/)
    .captures
    .map do |s|
      255 / (s.length == 2 ? s : s + s).to_i(16)
    rescue ::StandardError
      0
    end
end

Instance Attribute Details

#blueObject (readonly)

Returns the value of attribute blue.



6
7
8
# File 'lib/csv_plus_plus/color.rb', line 6

def blue
  @blue
end

#greenObject (readonly)

Returns the value of attribute green.



6
7
8
# File 'lib/csv_plus_plus/color.rb', line 6

def green
  @green
end

#redObject (readonly)

Returns the value of attribute red.



6
7
8
# File 'lib/csv_plus_plus/color.rb', line 6

def red
  @red
end