Class: Deskbot::Color

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/deskbot/color.rb

Class Method Summary collapse

Class Method Details

.from_hex(hex) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/deskbot/color.rb', line 20

def self.from_hex(hex)
  red, green, blue, alpha = hex
    .match(/^#(..)(..)(..)(..)?$/)
    .captures
    .map do |hex_pair|
      hex_pair&.hex
    end

  new(
    red:,
    green:,
    blue:,
    alpha: alpha || 255
  )
end