color_conversion 0.1.0 → 0.1.1
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 +7 -0
- data/Gemfile +0 -2
- data/README.md +48 -32
- data/lib/color_conversion/color.rb +1 -1
- data/lib/color_conversion/color_converter.rb +82 -62
- data/lib/color_conversion/converters/hsl_converter.rb +7 -1
- data/lib/color_conversion/converters/name_converter.rb +6 -1
- data/lib/color_conversion/version.rb +1 -1
- data/spec/color_converter_spec.rb +14 -2
- data/spec/converters/cmyk_converter_spec.rb +3 -3
- data/spec/converters/hex_converter_spec.rb +6 -6
- data/spec/converters/hsl_converter_spec.rb +11 -5
- data/spec/converters/hsl_string_converter_spec.rb +4 -4
- data/spec/converters/hsv_converter_spec.rb +5 -5
- data/spec/converters/name_converter_spec.rb +5 -5
- data/spec/converters/null_converter_spec.rb +3 -3
- data/spec/converters/rgb_converter_spec.rb +5 -5
- data/spec/converters/rgb_string_converter_spec.rb +4 -4
- metadata +21 -35
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f965f45721f6ef3f8f3817ba070dadac6404682594d0aabf77ab22ebd5d16208
|
4
|
+
data.tar.gz: 8b7bdd47f4d7d38d7b18cc142c05909941995378fe2b746a2ae429d4ed7bd903
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf2631f1b3e29c3d499b0790f3b570523c3c1a67e1abad3f96690c47833388cf72f994953e550d6c567122b40a665a95d9576598dd510c5d89cc2e5fa1e37327
|
7
|
+
data.tar.gz: dba487db8edf71d9895336eb603e3e42bdb77b1ade87a405f86e6a2d49ca8861ca0f8e2f6f4eac72dc8a27bafaead0809999255b9cb1f11d935528bd716c022c
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,51 +4,67 @@ This gem provides conversions for colors to and from Hex, RGB, and HSL.
|
|
4
4
|
|
5
5
|
## Examples
|
6
6
|
|
7
|
-
|
7
|
+
Initialize a color:
|
8
8
|
```ruby
|
9
9
|
# from hex
|
10
|
-
color = Color.new("#
|
11
|
-
color = Color.new("#
|
10
|
+
color = Color.new("#3366cc")
|
11
|
+
color = Color.new("#36c")
|
12
12
|
|
13
|
-
# from rgb
|
14
|
-
color = Color.new(r:
|
15
|
-
color = Color.new(r:
|
13
|
+
# from rgb(a)
|
14
|
+
color = Color.new(r: 51, g: 102, b: 204)
|
15
|
+
color = Color.new(r: 51, g: 102, b: 204, a: 0.5)
|
16
16
|
|
17
|
-
# from hsl
|
18
|
-
color = Color.new(h:
|
19
|
-
color = Color.new(h:
|
17
|
+
# from hsl(a)
|
18
|
+
color = Color.new(h: 225, s: 73, l: 57)
|
19
|
+
color = Color.new(h: 225, s: 73, l: 57, a: 0.5)
|
20
|
+
|
21
|
+
# from hsv/hsb
|
22
|
+
color = Color.new(h: 220, s: 75, v: 80)
|
23
|
+
color = Color.new(h: 220, s: 75, b: 80)
|
24
|
+
|
25
|
+
# from cmyk
|
26
|
+
color = Color.new(c: 74, m: 58, y: 22, k: 3)
|
20
27
|
|
21
28
|
# from textual color
|
22
|
-
color = Color.new("
|
29
|
+
color = Color.new("blue")
|
23
30
|
|
24
|
-
# from a css
|
25
|
-
color = Color.new("rgb(
|
26
|
-
color = Color.new("
|
31
|
+
# from a css rgb(a) string
|
32
|
+
color = Color.new("rgb(51, 102, 204)")
|
33
|
+
color = Color.new("rgba(51, 102, 204, 0.5)")
|
34
|
+
|
35
|
+
# from a css hsl(a) string
|
36
|
+
color = Color.new("hsl(225, 73%, 57%)")
|
37
|
+
color = Color.new("hsl(225, 73%, 57%, 0.5)")
|
27
38
|
```
|
28
39
|
|
40
|
+
Conversions
|
29
41
|
|
30
|
-
Convert to RGB
|
31
42
|
```ruby
|
32
|
-
Color.new(
|
33
|
-
=> {:r=>255, :g=>255, :b=>255}
|
34
|
-
```
|
43
|
+
color = Color.new(r: 70, g: 130, b: 180, a: 0.5)
|
35
44
|
|
36
|
-
|
37
|
-
|
38
|
-
Color.new("white").hex
|
39
|
-
=> "#FFFFFF"
|
40
|
-
```
|
45
|
+
color.alpha
|
46
|
+
=> 0.5
|
41
47
|
|
42
|
-
|
43
|
-
|
44
|
-
Color.new("white").hsl
|
45
|
-
=> {:h=>0, :s=>100, :l=>100}
|
46
|
-
```
|
48
|
+
color.rgb
|
49
|
+
=> {:r=>70, :g=>130, :b=>180}
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
color.hsl
|
52
|
+
=> {:h=>207, :s=>44, :l=>49}
|
53
|
+
|
54
|
+
color.hsv
|
55
|
+
=> {:h=>207, :s=>61, :v=>71}
|
56
|
+
|
57
|
+
color.hsb
|
58
|
+
=> {:h=>207, :s=>61, :b=>71}
|
59
|
+
|
60
|
+
color.cmyk
|
61
|
+
=> {:c=>61, :m=>28, :y=>0, :k=>29}
|
62
|
+
|
63
|
+
color.hex
|
64
|
+
=> "#4682b4"
|
65
|
+
|
66
|
+
color.name
|
67
|
+
=> "steelblue"
|
52
68
|
```
|
53
69
|
|
54
70
|
|
@@ -57,7 +73,7 @@ Color.new("#FFFFFF").name
|
|
57
73
|
To install ColorConversion, add the gem to your Gemfile:
|
58
74
|
|
59
75
|
```ruby
|
60
|
-
gem "color_conversion"
|
76
|
+
gem "color_conversion"
|
61
77
|
```
|
62
78
|
|
63
79
|
## LICENSE
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ColorConversion
|
2
2
|
class Color
|
3
3
|
extend Forwardable
|
4
|
-
def_delegators :@converter, :rgb, :hex, :hsl, :hsv, :hsb, :
|
4
|
+
def_delegators :@converter, :rgb, :hex, :hsl, :hsv, :hsb, :cmyk, :alpha
|
5
5
|
|
6
6
|
def initialize(color)
|
7
7
|
@converter = ColorConverter.factory(color)
|
@@ -33,65 +33,15 @@ module ColorConversion
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def hsl
|
36
|
-
r
|
37
|
-
g = @rgba[:g] / 255.0
|
38
|
-
b = @rgba[:b] / 255.0
|
39
|
-
min = [r, g, b].min
|
40
|
-
max = [r, g, b].max
|
41
|
-
delta = max - min
|
36
|
+
@r, @g, @b = rgb_array_frac
|
42
37
|
|
43
|
-
h
|
44
|
-
0
|
45
|
-
elsif r == max
|
46
|
-
(g - b) / delta
|
47
|
-
elsif g == max
|
48
|
-
2 + (b - r) / delta
|
49
|
-
elsif b == max
|
50
|
-
4 + (r - g) / delta
|
51
|
-
end
|
52
|
-
|
53
|
-
h = [h * 60, 360].min
|
54
|
-
h += 360 if h < 0
|
55
|
-
l = (min + max) / 2.0
|
56
|
-
|
57
|
-
s = if (max == min)
|
58
|
-
0
|
59
|
-
elsif (l <= 0.5)
|
60
|
-
delta / (max + min)
|
61
|
-
else
|
62
|
-
delta / (2.0 - max - min)
|
63
|
-
end
|
64
|
-
|
65
|
-
{h: h.round, s: (s * 100).round, l: (l * 100).round}
|
38
|
+
{h: hue, s: hsl_saturation, l: hsl_lightness}
|
66
39
|
end
|
67
|
-
|
68
|
-
def hsv
|
69
|
-
r = @rgba[:r].to_f
|
70
|
-
g = @rgba[:g].to_f
|
71
|
-
b = @rgba[:b].to_f
|
72
|
-
min = [r, g, b].min
|
73
|
-
|
74
|
-
max = [r, g, b].max
|
75
|
-
delta = (max - min).to_f
|
76
|
-
|
77
|
-
s = max == 0 ? 0 : (delta / max * 1000) / 10.0
|
78
|
-
|
79
|
-
h = if max == min
|
80
|
-
0
|
81
|
-
elsif r == max
|
82
|
-
(g - b) / delta
|
83
|
-
elsif g == max
|
84
|
-
2 + (b - r) / delta
|
85
|
-
elsif b == max
|
86
|
-
4 + (r - g) / delta
|
87
|
-
end
|
88
|
-
|
89
|
-
h = [h * 60, 360].min
|
90
|
-
h += 360 if h < 0
|
91
40
|
|
92
|
-
|
41
|
+
def hsv
|
42
|
+
@r, @g, @b = rgb_array
|
93
43
|
|
94
|
-
{h:
|
44
|
+
{h: hue, s: hsv_saturation, v: hsv_value}
|
95
45
|
end
|
96
46
|
|
97
47
|
def hsb
|
@@ -101,14 +51,12 @@ module ColorConversion
|
|
101
51
|
end
|
102
52
|
|
103
53
|
def cmyk
|
104
|
-
r
|
105
|
-
g = @rgba[:g] / 255.0
|
106
|
-
b = @rgba[:b] / 255.0
|
54
|
+
@r, @g, @b = rgb_array_frac
|
107
55
|
|
108
|
-
k = [1.0 - r, 1.0 - g, 1.0 - b].min
|
109
|
-
c = (1.0 - r - k) / (1.0 - k)
|
110
|
-
m = (1.0 - g - k) / (1.0 - k)
|
111
|
-
y = (1.0 - b - k) / (1.0 - k)
|
56
|
+
k = [1.0 - @r, 1.0 - @g, 1.0 - @b].min
|
57
|
+
c = (1.0 - @r - k) / (1.0 - k)
|
58
|
+
m = (1.0 - @g - k) / (1.0 - k)
|
59
|
+
y = (1.0 - @b - k) / (1.0 - k)
|
112
60
|
|
113
61
|
{c: (c * 100).round,
|
114
62
|
m: (m * 100).round,
|
@@ -119,6 +67,78 @@ module ColorConversion
|
|
119
67
|
def alpha
|
120
68
|
@rgba[:a]
|
121
69
|
end
|
70
|
+
|
71
|
+
def name
|
72
|
+
NameConverter.name_for_rgb(rgb)
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
protected
|
77
|
+
|
78
|
+
def rgb_array
|
79
|
+
[@rgba[:r].to_f, @rgba[:g].to_f, @rgba[:b].to_f]
|
80
|
+
end
|
81
|
+
|
82
|
+
def rgb_array_frac
|
83
|
+
[@rgba[:r] / 255.0, @rgba[:g] / 255.0, @rgba[:b] / 255.0]
|
84
|
+
end
|
85
|
+
|
86
|
+
def min
|
87
|
+
[@r, @g, @b].min
|
88
|
+
end
|
89
|
+
|
90
|
+
def max
|
91
|
+
[@r, @g, @b].max
|
92
|
+
end
|
93
|
+
|
94
|
+
def delta
|
95
|
+
max - min
|
96
|
+
end
|
97
|
+
|
98
|
+
def hue
|
99
|
+
h = if max == min
|
100
|
+
0
|
101
|
+
elsif @r == max
|
102
|
+
(@g - @b) / delta
|
103
|
+
elsif @g == max
|
104
|
+
2 + (@b - @r) / delta
|
105
|
+
elsif @b == max
|
106
|
+
4 + (@r - @g) / delta
|
107
|
+
end
|
108
|
+
|
109
|
+
h = [h * 60, 360].min
|
110
|
+
h += 360 if h < 0
|
111
|
+
h.round
|
112
|
+
end
|
113
|
+
|
114
|
+
# hsv
|
115
|
+
def hsv_saturation
|
116
|
+
sat = max == 0 ? 0 : (delta / max * 1000) / 10.0
|
117
|
+
sat.round
|
118
|
+
end
|
119
|
+
|
120
|
+
def hsv_value
|
121
|
+
val = ((max / 255.0) * 1000) / 10.0
|
122
|
+
val.round
|
123
|
+
end
|
124
|
+
|
125
|
+
# hsl
|
126
|
+
def hsl_saturation
|
127
|
+
s = if max == min
|
128
|
+
0
|
129
|
+
elsif hsl_lightness / 100.0 <= 0.5
|
130
|
+
delta / (max + min)
|
131
|
+
else
|
132
|
+
delta / (2.0 - max - min)
|
133
|
+
end
|
134
|
+
|
135
|
+
(s * 100).round
|
136
|
+
end
|
137
|
+
|
138
|
+
def hsl_lightness
|
139
|
+
light = (min + max) / 2.0 * 100
|
140
|
+
light.round
|
141
|
+
end
|
122
142
|
|
123
143
|
end
|
124
144
|
end
|
@@ -15,7 +15,7 @@ module ColorConversion
|
|
15
15
|
l = hsl[:l].to_s.gsub(/[^0-9\.]/, "").to_f / 100.0
|
16
16
|
a = hsl[:a] ? hsl[:a].to_s.gsub(/[^0-9\.]/, "").to_f : 1.0
|
17
17
|
|
18
|
-
return
|
18
|
+
return greyscale(l, a) if s == 0
|
19
19
|
|
20
20
|
t2 = if l < 0.5
|
21
21
|
l * (1 + s)
|
@@ -47,5 +47,11 @@ module ColorConversion
|
|
47
47
|
|
48
48
|
{r: rgb[0], g: rgb[1], b: rgb[2], a: a}
|
49
49
|
end
|
50
|
+
|
51
|
+
def greyscale(luminosity, alpha)
|
52
|
+
rgb_equal_value = (luminosity * 255).round
|
53
|
+
{ r: rgb_equal_value, g: rgb_equal_value, b: rgb_equal_value, a: alpha }
|
54
|
+
end
|
55
|
+
|
50
56
|
end
|
51
57
|
end
|
@@ -6,6 +6,11 @@ module ColorConversion
|
|
6
6
|
|
7
7
|
color_names.include?(color.downcase.to_sym)
|
8
8
|
end
|
9
|
+
|
10
|
+
def self.name_for_rgb(rgb)
|
11
|
+
name = color_names.find {|k,v| v == [rgb[:r], rgb[:g], rgb[:b]] }
|
12
|
+
name[0].to_s if name
|
13
|
+
end
|
9
14
|
|
10
15
|
private
|
11
16
|
|
@@ -13,7 +18,7 @@ module ColorConversion
|
|
13
18
|
rgb = self.class.color_names[name.downcase.to_sym]
|
14
19
|
{r: rgb[0], g: rgb[1], b: rgb[2], a: 1.0}
|
15
20
|
end
|
16
|
-
|
21
|
+
|
17
22
|
def self.color_names
|
18
23
|
{aliceblue: [240,248,255],
|
19
24
|
antiquewhite: [250,235,215],
|
@@ -45,8 +45,8 @@ describe ColorConverter do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
describe ".
|
49
|
-
it "converts color to
|
48
|
+
describe ".cmyk" do
|
49
|
+
it "converts color to cmyk" do
|
50
50
|
conv = RgbConverter.new(r: 64, g: 104, b: 193)
|
51
51
|
|
52
52
|
cmyk = {c: 67, m: 46, y: 0, k: 24}
|
@@ -54,6 +54,18 @@ describe ColorConverter do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
describe ".name" do
|
58
|
+
it "converts color to name" do
|
59
|
+
conv = RgbConverter.new(r: 255, g: 0, b: 0)
|
60
|
+
expect(conv.name).to eq "red"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns nil if no name found" do
|
64
|
+
conv = RgbConverter.new(r: 255, g: 0, b: 1)
|
65
|
+
expect(conv.name).to be_nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
57
69
|
describe ".alpha" do
|
58
70
|
it "finds alpha for color" do
|
59
71
|
conv = RgbConverter.new(r: 51, g: 102, b: 204, a: 0.5)
|
@@ -3,15 +3,15 @@ require 'spec_helper'
|
|
3
3
|
describe CmykConverter do
|
4
4
|
describe ".matches?" do
|
5
5
|
it "should match args with cmyk hash" do
|
6
|
-
expect(CmykConverter.matches?(c: 87, m: 69, y: 13, k: 1)).to
|
6
|
+
expect(CmykConverter.matches?(c: 87, m: 69, y: 13, k: 1)).to be true
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should not match args without cmyk hash" do
|
10
|
-
expect(CmykConverter.matches?(h: 225, s: 73, v: 57)).to
|
10
|
+
expect(CmykConverter.matches?(h: 225, s: 73, v: 57)).to be false
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should not match a string" do
|
14
|
-
expect(CmykConverter.matches?("#ffffff")).to
|
14
|
+
expect(CmykConverter.matches?("#ffffff")).to be false
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -3,23 +3,23 @@ require 'spec_helper'
|
|
3
3
|
describe HexConverter do
|
4
4
|
describe ".matches?" do
|
5
5
|
it "should match args with hex string" do
|
6
|
-
expect(HexConverter.matches?("#FFFFFF")).to
|
6
|
+
expect(HexConverter.matches?("#FFFFFF")).to be true
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should match args with short hex string" do
|
10
|
-
expect(HexConverter.matches?("#FFF")).to
|
10
|
+
expect(HexConverter.matches?("#FFF")).to be true
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should match args with lower case hex string" do
|
14
|
-
expect(HexConverter.matches?("#ffffff")).to
|
14
|
+
expect(HexConverter.matches?("#ffffff")).to be true
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should not match args without hex string" do
|
18
|
-
expect(HexConverter.matches?("asdf")).to
|
18
|
+
expect(HexConverter.matches?("asdf")).to be false
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should not match args without hex string" do
|
22
|
-
expect(HexConverter.matches?(h: 225, s: 73, l: 57)).to
|
22
|
+
expect(HexConverter.matches?(h: 225, s: 73, l: 57)).to be false
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -30,4 +30,4 @@ describe HexConverter do
|
|
30
30
|
expect(conv.rgba).to eq rgba
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
@@ -3,19 +3,19 @@ require 'spec_helper'
|
|
3
3
|
describe HslConverter do
|
4
4
|
describe ".matches?" do
|
5
5
|
it "should match args with hsl hash" do
|
6
|
-
expect(HslConverter.matches?(h: 225, s: 73, l: 57)).to
|
6
|
+
expect(HslConverter.matches?(h: 225, s: 73, l: 57)).to be true
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should match args with hsla hash" do
|
10
|
-
expect(HslConverter.matches?(h: 225, s: 73, l: 57, a: 0.5)).to
|
10
|
+
expect(HslConverter.matches?(h: 225, s: 73, l: 57, a: 0.5)).to be true
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should not match args without hsl hash" do
|
14
|
-
expect(HslConverter.matches?(h: 225, s: 73, v: 57)).to
|
14
|
+
expect(HslConverter.matches?(h: 225, s: 73, v: 57)).to be false
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should not match a string" do
|
18
|
-
expect(HslConverter.matches?("#ffffff")).to
|
18
|
+
expect(HslConverter.matches?("#ffffff")).to be false
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -37,5 +37,11 @@ describe HslConverter do
|
|
37
37
|
rgba = {r: 65, g: 105, b: 225, a: 0.5}
|
38
38
|
expect(conv.rgba).to eq rgba
|
39
39
|
end
|
40
|
+
|
41
|
+
it 'should return equal values when saturation is 0' do
|
42
|
+
conv = HslConverter.new(h: "225", s: "0%", l: "20%", a: "0.5")
|
43
|
+
rgba = {r: 51, g: 51, b: 51, a: 0.5}
|
44
|
+
expect(conv.rgba).to eq rgba
|
45
|
+
end
|
40
46
|
end
|
41
|
-
end
|
47
|
+
end
|
@@ -3,15 +3,15 @@ require 'spec_helper'
|
|
3
3
|
describe HslStringConverter do
|
4
4
|
describe ".matches?" do
|
5
5
|
it "should match args with hsl string" do
|
6
|
-
expect(HslStringConverter.matches?("hsl(225, 73%, 57%)")).to
|
6
|
+
expect(HslStringConverter.matches?("hsl(225, 73%, 57%)")).to be true
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should match args with hsla string" do
|
10
|
-
expect(HslStringConverter.matches?("hsla(225, 73%, 57%, 0.5)")).to
|
10
|
+
expect(HslStringConverter.matches?("hsla(225, 73%, 57%, 0.5)")).to be true
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should not match args without hsl string" do
|
14
|
-
expect(HslStringConverter.matches?(h: 225, s: 73, l: 57)).to
|
14
|
+
expect(HslStringConverter.matches?(h: 225, s: 73, l: 57)).to be false
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -28,4 +28,4 @@ describe HslStringConverter do
|
|
28
28
|
expect(conv.rgba).to eq rgba
|
29
29
|
end
|
30
30
|
end
|
31
|
-
end
|
31
|
+
end
|
@@ -3,19 +3,19 @@ require 'spec_helper'
|
|
3
3
|
describe HsvConverter do
|
4
4
|
describe ".matches?" do
|
5
5
|
it "should match args with hsv hash" do
|
6
|
-
expect(HsvConverter.matches?(h: 225, s: 73, v: 57)).to
|
6
|
+
expect(HsvConverter.matches?(h: 225, s: 73, v: 57)).to be true
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should match args with hsb hash" do
|
10
|
-
expect(HsvConverter.matches?(h: 225, s: 73, b: 57)).to
|
10
|
+
expect(HsvConverter.matches?(h: 225, s: 73, b: 57)).to be true
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should not match args without hsv hash" do
|
14
|
-
expect(HsvConverter.matches?(h: 225, s: 73, l: 57)).to
|
14
|
+
expect(HsvConverter.matches?(h: 225, s: 73, l: 57)).to be false
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should not match a string" do
|
18
|
-
expect(HsvConverter.matches?("#ffffff")).to
|
18
|
+
expect(HsvConverter.matches?("#ffffff")).to be false
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -33,4 +33,4 @@ describe HsvConverter do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
36
|
-
end
|
36
|
+
end
|
@@ -3,16 +3,16 @@ require 'spec_helper'
|
|
3
3
|
describe NameConverter do
|
4
4
|
describe ".matches?" do
|
5
5
|
it "should match args with name string" do
|
6
|
-
expect(NameConverter.matches?("blue")).to
|
6
|
+
expect(NameConverter.matches?("blue")).to be true
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should match args with color insensitive string" do
|
10
|
-
expect(NameConverter.matches?("RoyalBlue")).to
|
11
|
-
expect(NameConverter.matches?("royalblue")).to
|
10
|
+
expect(NameConverter.matches?("RoyalBlue")).to be true
|
11
|
+
expect(NameConverter.matches?("royalblue")).to be true
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should not match args without name string" do
|
15
|
-
expect(NameConverter.matches?("#ffffff")).to
|
15
|
+
expect(NameConverter.matches?("#ffffff")).to be false
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -23,4 +23,4 @@ describe NameConverter do
|
|
23
23
|
expect(conv.rgba).to eq rgba
|
24
24
|
end
|
25
25
|
end
|
26
|
-
end
|
26
|
+
end
|
@@ -3,8 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe NullConverter do
|
4
4
|
describe ".matches?" do
|
5
5
|
it "should always match" do
|
6
|
-
expect(NullConverter.matches?("blue")).to
|
7
|
-
expect(NullConverter.matches?(r: 51, g: 102, b: 204)).to
|
6
|
+
expect(NullConverter.matches?("blue")).to be true
|
7
|
+
expect(NullConverter.matches?(r: 51, g: 102, b: 204)).to be true
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -16,4 +16,4 @@ describe NullConverter do
|
|
16
16
|
}.to raise_error(InvalidColorError)
|
17
17
|
end
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
@@ -3,19 +3,19 @@ require 'spec_helper'
|
|
3
3
|
describe RgbConverter do
|
4
4
|
describe ".matches?" do
|
5
5
|
it "should match args with rgb hash" do
|
6
|
-
expect(RgbConverter.matches?(r: 51, g: 102, b: 204)).to
|
6
|
+
expect(RgbConverter.matches?(r: 51, g: 102, b: 204)).to be true
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should match args with rgba hash" do
|
10
|
-
expect(RgbConverter.matches?(r: 51, g: 102, b: 204, a: 0.5)).to
|
10
|
+
expect(RgbConverter.matches?(r: 51, g: 102, b: 204, a: 0.5)).to be true
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should not match args without rgb hash" do
|
14
|
-
expect(RgbConverter.matches?(h: 225, s: 73, l: 57)).to
|
14
|
+
expect(RgbConverter.matches?(h: 225, s: 73, l: 57)).to be false
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should not match a string" do
|
18
|
-
expect(RgbConverter.matches?("#ffffff")).to
|
18
|
+
expect(RgbConverter.matches?("#ffffff")).to be false
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -38,4 +38,4 @@ describe RgbConverter do
|
|
38
38
|
expect(conv.rgba).to eq rgba
|
39
39
|
end
|
40
40
|
end
|
41
|
-
end
|
41
|
+
end
|
@@ -3,15 +3,15 @@ require 'spec_helper'
|
|
3
3
|
describe RgbStringConverter do
|
4
4
|
describe ".matches?" do
|
5
5
|
it "should match args with rgb string" do
|
6
|
-
expect(RgbStringConverter.matches?("rgb(51, 102, 204)")).to
|
6
|
+
expect(RgbStringConverter.matches?("rgb(51, 102, 204)")).to be true
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should match args with rgba string" do
|
10
|
-
expect(RgbStringConverter.matches?("rgba(51, 102, 204, 0.2)")).to
|
10
|
+
expect(RgbStringConverter.matches?("rgba(51, 102, 204, 0.2)")).to be true
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should not match args without rgb string" do
|
14
|
-
expect(RgbStringConverter.matches?(r: 51, g: 102, b: 204)).to
|
14
|
+
expect(RgbStringConverter.matches?(r: 51, g: 102, b: 204)).to be false
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -42,4 +42,4 @@ describe RgbStringConverter do
|
|
42
42
|
}.to raise_error(InvalidColorError)
|
43
43
|
end
|
44
44
|
end
|
45
|
-
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,94 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: color_conversion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Derek DeVries
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2022-01-12 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '2.9'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '2.9'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: guard
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- - ~>
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '1.7'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- - ~>
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '1.7'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: guard-rspec
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- - ~>
|
59
|
+
- - "~>"
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '2.5'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- - ~>
|
66
|
+
- - "~>"
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '2.5'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rb-fsevent
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- - ~>
|
73
|
+
- - "~>"
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0.9'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- - ~>
|
80
|
+
- - "~>"
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0.9'
|
94
83
|
description: Convert colors to hex/rgb/hsv
|
@@ -98,7 +87,7 @@ executables: []
|
|
98
87
|
extensions: []
|
99
88
|
extra_rdoc_files: []
|
100
89
|
files:
|
101
|
-
- .gitignore
|
90
|
+
- ".gitignore"
|
102
91
|
- Gemfile
|
103
92
|
- Guardfile
|
104
93
|
- LICENSE.txt
|
@@ -135,27 +124,25 @@ files:
|
|
135
124
|
homepage: https://github.com/devrieda/color_conversion
|
136
125
|
licenses:
|
137
126
|
- MIT
|
138
|
-
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
139
129
|
rdoc_options: []
|
140
130
|
require_paths:
|
141
131
|
- lib
|
142
132
|
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
-
none: false
|
144
133
|
requirements:
|
145
|
-
- -
|
134
|
+
- - ">="
|
146
135
|
- !ruby/object:Gem::Version
|
147
136
|
version: 1.9.3
|
148
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
-
none: false
|
150
138
|
requirements:
|
151
|
-
- -
|
139
|
+
- - ">="
|
152
140
|
- !ruby/object:Gem::Version
|
153
141
|
version: '0'
|
154
142
|
requirements: []
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
specification_version: 3
|
143
|
+
rubygems_version: 3.2.22
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
159
146
|
summary: Convert colors to hex/rgb/hsv
|
160
147
|
test_files:
|
161
148
|
- spec/color_converter_spec.rb
|
@@ -171,4 +158,3 @@ test_files:
|
|
171
158
|
- spec/converters/rgb_string_converter_spec.rb
|
172
159
|
- spec/spec_helper.rb
|
173
160
|
- spec/version_spec.rb
|
174
|
-
has_rdoc:
|