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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 442a64b120cdb40e5bfa18621c562efc6123e39c
4
- data.tar.gz: fa1c2799e3c17ee6e975b86a0c370b010be30259
3
+ metadata.gz: 078de94b631215783ac2ddf0144f703915bdc0ba
4
+ data.tar.gz: 972abe37b77128bcfdcc09b22225a4ae8ea70715
5
5
  SHA512:
6
- metadata.gz: aba381518ae63810146cfe1ef24558743a56111db72e21f5638022ccf76672098c765e989ff7c621095927f17d1765ad49fe004b6d75666217644aca36c31a2d
7
- data.tar.gz: 107b80dad0783546d9cf575368c658ff1dbfd074c76ebd16cbadbbeb46712020e5516eb45c8b13a557e5d1abea971113caa7a5eae5830bff514b68f94b79d9f4
6
+ metadata.gz: ad5f5e9c72ec171f64277e6603fecb44f4c20a447a13dcf7ce24b8aa767f8037ed34c3230177bb1c819a36af1e3982ed977e099881b79b00ec240d4e54f15593
7
+ data.tar.gz: 8153367a9db6c4d059f13a9de12feaf0de7e78d9c53e546de7ea2a3c5daf648fa787d87aa533506e656f60a3e4b380895030acdb8957d91c00bc758d129d56d7
@@ -1,3 +1,3 @@
1
1
  module HexToRgba
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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 color.length == 3
12
- red = (color[0]*2).to_i 16
13
- green = (color[1]*2).to_i 16
14
- blue = (color[2]*2).to_i 16
15
- elsif color.length == 6
16
- red = color[0..1].to_i 16
17
- green = color[3..4].to_i 16
18
- blue = color[5..6].to_i 16
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hex_to_rgba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Zhuk