color_converter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/color_converter.rb +37 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 23fbf128c1e7270acea9239e5fb1c2b484f924cf
|
4
|
+
data.tar.gz: ad5670ef086a8f0bb784ce2ab459228d9ecc000a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 817dfa445bf222fbdf5427aa9f1f9fe1a54a26cc778443f4c7fb238707620356d34382847c7512d178a5ffc65f3b336d19510e1dafe09e602cfda516c99e0cec
|
7
|
+
data.tar.gz: 1917c7c2ed7bcb2ea267cffa4c8805dd71c497bbc29d371b80e8a4c4ce98facbd4d7d20f8e876a15b9ac02327804417fa10f97838951bda4efd1b1ebb37f6136
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module ColorConverter
|
4
|
+
|
5
|
+
def self.hex_to_rgb hex
|
6
|
+
hex.sub! '#', ''
|
7
|
+
|
8
|
+
if hex.size === 3
|
9
|
+
return makes_rgb(hex[0] + hex[0], hex[1] + hex[1],
|
10
|
+
hex[2] + hex[2])
|
11
|
+
end
|
12
|
+
|
13
|
+
result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.match(hex)
|
14
|
+
|
15
|
+
return nil if result.nil?
|
16
|
+
|
17
|
+
makes_rgb result[1], result[2], result[3]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.rgb_to_hex rgb
|
21
|
+
r = rgb[:r]
|
22
|
+
g = rgb[:g]
|
23
|
+
b = rgb[:b]
|
24
|
+
|
25
|
+
"##{r.to_s(16)}#{g.to_s 16}#{b.to_s 16}".upcase
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def self.makes_rgb r, g, b
|
30
|
+
{
|
31
|
+
r: r.to_i(16),
|
32
|
+
g: g.to_i(16),
|
33
|
+
b: b.to_i(16)
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: color_converter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- EvandroLG
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: color_converter is a Ruby module that help you to convert RGB/hexadecimal
|
14
|
+
color models
|
15
|
+
email: evandrolgoncalves@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/color_converter.rb
|
21
|
+
homepage: https://github.com/EvandroLG/color_converter
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.5.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: color_converter
|
45
|
+
test_files: []
|