Module: RGB
- Defined in:
- lib/color/rgb.rb
Overview
Offering functionality related to the RGB color model.
Class Method Summary collapse
- .convert_decimal_to_2_digit_hex(dec) ⇒ Object
- .hex_to_dec(hex) ⇒ Object
- .hex_to_rgb(hex_color) ⇒ Object
- .rgb_to_hex(rgb_color) ⇒ Object
Class Method Details
.convert_decimal_to_2_digit_hex(dec) ⇒ Object
23 24 25 26 27 |
# File 'lib/color/rgb.rb', line 23 def self.convert_decimal_to_2_digit_hex(dec) hex = dec.to_s(16) hex *= 2 if hex.length == 1 hex end |
.hex_to_dec(hex) ⇒ Object
14 15 16 |
# File 'lib/color/rgb.rb', line 14 def self.hex_to_dec(hex) (hex[0].to_i(16) * 16) + hex[1].to_i(16) end |
.hex_to_rgb(hex_color) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/color/rgb.rb', line 7 def self.hex_to_rgb(hex_color) hex_color = Hex.fill_hex_color(hex_color) if hex_color.length == 4 # Length 4 => #aac [hex_to_dec(hex_color[1..2]), hex_to_dec(hex_color[3..4]), hex_to_dec(hex_color[5..6])] end |
.rgb_to_hex(rgb_color) ⇒ Object
18 19 20 21 |
# File 'lib/color/rgb.rb', line 18 def self.rgb_to_hex(rgb_color) hex = "#".dup << convert_decimal_to_2_digit_hex(rgb_color[0]) hex << convert_decimal_to_2_digit_hex(rgb_color[1]) << convert_decimal_to_2_digit_hex(rgb_color[2]) end |