Class: Workarea::Storefront::ColorTools

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/storefront/color_tools.rb

Instance Method Summary collapse

Constructor Details

#initialize(color) ⇒ ColorTools

Returns a new instance of ColorTools.



4
5
6
# File 'app/services/workarea/storefront/color_tools.rb', line 4

def initialize(color)
  @color = color
end

Instance Method Details

#alphaObject



14
15
16
# File 'app/services/workarea/storefront/color_tools.rb', line 14

def alpha
  @color[:alpha].to_f / 100.0
end

#hex_to_rgbObject



18
19
20
21
# File 'app/services/workarea/storefront/color_tools.rb', line 18

def hex_to_rgb
  r, g, b = @color[:hex].match(/#(..)(..)(..)/).captures
  "#{r.hex}, #{g.hex}, #{b.hex}"
end

#rgbaObject



8
9
10
11
12
# File 'app/services/workarea/storefront/color_tools.rb', line 8

def rgba
  if @color[:hex] =~ /#(..)(..)(..)/
    "#{hex_to_rgb}, #{alpha}"
  end
end