hex_to_rgba 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/hex_to_rgba/version.rb +1 -1
- data/lib/hex_to_rgba.rb +14 -10
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 078de94b631215783ac2ddf0144f703915bdc0ba
|
|
4
|
+
data.tar.gz: 972abe37b77128bcfdcc09b22225a4ae8ea70715
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad5f5e9c72ec171f64277e6603fecb44f4c20a447a13dcf7ce24b8aa767f8037ed34c3230177bb1c819a36af1e3982ed977e099881b79b00ec240d4e54f15593
|
|
7
|
+
data.tar.gz: 8153367a9db6c4d059f13a9de12feaf0de7e78d9c53e546de7ea2a3c5daf648fa787d87aa533506e656f60a3e4b380895030acdb8957d91c00bc758d129d56d7
|
data/lib/hex_to_rgba/version.rb
CHANGED
data/lib/hex_to_rgba.rb
CHANGED
|
@@ -2,20 +2,24 @@ require "hex_to_rgba/version"
|
|
|
2
2
|
|
|
3
3
|
module HexToRgba
|
|
4
4
|
class Converter
|
|
5
|
-
attr_accessor :color, :opacity
|
|
6
|
-
|
|
7
5
|
def self.convert color, opacity
|
|
6
|
+
if color.to_s.include? '#'
|
|
7
|
+
hexadecimal_color = color.delete '#'
|
|
8
|
+
else
|
|
9
|
+
hexadecimal_color = color
|
|
10
|
+
end
|
|
11
|
+
|
|
8
12
|
if (/([a-fA-F]|[0-9]){3,6}/ =~ color).nil?
|
|
9
13
|
'Wrong color format'
|
|
10
14
|
else
|
|
11
|
-
if
|
|
12
|
-
red = (
|
|
13
|
-
green = (
|
|
14
|
-
blue = (
|
|
15
|
-
elsif
|
|
16
|
-
red =
|
|
17
|
-
green =
|
|
18
|
-
blue =
|
|
15
|
+
if hexadecimal_color.length == 3
|
|
16
|
+
red = (hexadecimal_color[0]*2).to_i 16
|
|
17
|
+
green = (hexadecimal_color[1]*2).to_i 16
|
|
18
|
+
blue = (hexadecimal_color[2]*2).to_i 16
|
|
19
|
+
elsif hexadecimal_color.length == 6
|
|
20
|
+
red = hexadecimal_color[0..1].to_i 16
|
|
21
|
+
green = hexadecimal_color[3..4].to_i 16
|
|
22
|
+
blue = hexadecimal_color[5..6].to_i 16
|
|
19
23
|
else
|
|
20
24
|
'Wrong color format'
|
|
21
25
|
end
|