Class: CSVPlusPlus::Color
- Inherits:
-
Object
- Object
- CSVPlusPlus::Color
- Defined in:
- lib/csv_plus_plus/color.rb
Overview
A color value
Instance Attribute Summary collapse
-
#blue ⇒ Object
readonly
Returns the value of attribute blue.
-
#green ⇒ Object
readonly
Returns the value of attribute green.
-
#red ⇒ Object
readonly
Returns the value of attribute red.
Instance Method Summary collapse
-
#initialize(hex_string) ⇒ Color
constructor
create an instance from a string like “#FFF” or “#FFFFFF”.
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
#blue ⇒ Object (readonly)
Returns the value of attribute blue.
6 7 8 |
# File 'lib/csv_plus_plus/color.rb', line 6 def blue @blue end |
#green ⇒ Object (readonly)
Returns the value of attribute green.
6 7 8 |
# File 'lib/csv_plus_plus/color.rb', line 6 def green @green end |
#red ⇒ Object (readonly)
Returns the value of attribute red.
6 7 8 |
# File 'lib/csv_plus_plus/color.rb', line 6 def red @red end |