Class: Falu::Colors::HEX
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #blue ⇒ Object
- #colors ⇒ Object
- #green ⇒ Object
-
#initialize(*color, rgb: nil, hsl: nil) ⇒ HEX
constructor
A new instance of HEX.
- #red ⇒ Object
- #to_a ⇒ Object
- #to_h ⇒ Object
- #to_hex ⇒ Object
- #to_hsl ⇒ Object
- #to_rgb ⇒ Object
- #to_s ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(*color, rgb: nil, hsl: nil) ⇒ HEX
Returns a new instance of HEX.
6 7 8 9 10 |
# File 'lib/falu/colors/hex.rb', line 6 def initialize(*color, rgb: nil, hsl: nil) color = color[0] if color.length == 1 raise "Invalid HEX Color: #{color.to_s}" unless Falu::Color.hex?(color) @color = color.is_a?(Array) ? color.join : color end |
Instance Method Details
#blue ⇒ Object
27 28 29 |
# File 'lib/falu/colors/hex.rb', line 27 def blue colors[2] end |
#colors ⇒ Object
12 13 14 15 16 17 |
# File 'lib/falu/colors/hex.rb', line 12 def colors @colors ||= begin match = color.to_s.match(/#?([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})/) match[1..3] unless match.nil? end end |
#green ⇒ Object
23 24 25 |
# File 'lib/falu/colors/hex.rb', line 23 def green colors[1] end |
#red ⇒ Object
19 20 21 |
# File 'lib/falu/colors/hex.rb', line 19 def red colors[0] end |
#to_a ⇒ Object
35 36 37 |
# File 'lib/falu/colors/hex.rb', line 35 def to_a colors end |
#to_h ⇒ Object
39 40 41 |
# File 'lib/falu/colors/hex.rb', line 39 def to_h {red: red, green: green, blue: blue} end |
#to_hex ⇒ Object
43 44 45 |
# File 'lib/falu/colors/hex.rb', line 43 def to_hex self end |
#to_hsl ⇒ Object
51 52 53 |
# File 'lib/falu/colors/hex.rb', line 51 def to_hsl to_rgb.to_hsl end |
#to_rgb ⇒ Object
47 48 49 |
# File 'lib/falu/colors/hex.rb', line 47 def to_rgb Falu::Colors::RGB.new(colors.map { |c| c.to_i(16) }) end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/falu/colors/hex.rb', line 31 def to_s "##{colors.join}" end |