color_conversion 0.1.1 → 0.1.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/color_conversion/color.rb +7 -1
- data/lib/color_conversion/version.rb +1 -1
- data/spec/color_spec.rb +71 -23
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67ef203f22ffbece2c150be570dcd841c9ea476da8352afaa41b1ea1988ca7b9
|
4
|
+
data.tar.gz: 17f62d21d1073db851c7d0e732b32d1f3b36637ae27bbf781a3e869c58c65dad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dbacd4819c95094cfc6a296b1503a8950b7fdf9a50b3eba26cbd3613a8b07d0c2e0f257db45e202d4081f90944e60f1045f0e8569dc6456c66475ab1e39313c
|
7
|
+
data.tar.gz: 98beb5c98f321f891af4f06d49bd6b629417a886894c2e1d803335daf6e960d3c17dc31190f4b1734e0d8cef8ceec399f63b613be4cbc2564719a6bf812e1c35
|
data/spec/color_spec.rb
CHANGED
@@ -1,94 +1,142 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Color do
|
4
|
-
|
5
|
-
describe ".new with color string" do
|
3
|
+
describe Color do
|
6
4
|
|
7
|
-
|
5
|
+
describe ".new with color string" do
|
6
|
+
|
7
|
+
it "should initialize color by lower hex" do
|
8
8
|
color = Color.new("#3366cc")
|
9
9
|
expect(color.rgb).to eq(r: 51, g: 102, b: 204)
|
10
10
|
end
|
11
11
|
|
12
|
-
it "should initialize color by hex with hash" do
|
12
|
+
it "should initialize color by hex with hash" do
|
13
13
|
color = Color.new("#3366CC")
|
14
14
|
expect(color.rgb).to eq(r: 51, g: 102, b: 204)
|
15
15
|
end
|
16
16
|
|
17
|
-
it "should initialize color by short hex" do
|
17
|
+
it "should initialize color by short hex" do
|
18
18
|
color = Color.new("#36C")
|
19
19
|
expect(color.rgb).to eq(r: 51, g: 102, b: 204)
|
20
20
|
end
|
21
21
|
|
22
|
-
it "should initialize color by rgb string" do
|
22
|
+
it "should initialize color by rgb string" do
|
23
23
|
color = Color.new("rgb(51, 102, 204)")
|
24
24
|
expect(color.rgb).to eq(r: 51, g: 102, b: 204)
|
25
25
|
end
|
26
26
|
|
27
|
-
it "should initialize color by rgba string" do
|
27
|
+
it "should initialize color by rgba string" do
|
28
28
|
color = Color.new("rgba(51, 102, 204, 0.2)")
|
29
29
|
expect(color.rgb).to eq(r: 51, g: 102, b: 204)
|
30
30
|
expect(color.alpha).to eq 0.2
|
31
31
|
end
|
32
32
|
|
33
|
-
it "should initialize color by hsl string" do
|
33
|
+
it "should initialize color by hsl string" do
|
34
34
|
color = Color.new("hsl(225, 73%, 57%)")
|
35
35
|
expect(color.rgb).to eq(r: 65, g: 105, b: 225)
|
36
36
|
end
|
37
37
|
|
38
|
-
it "should initialize color by hsla string" do
|
39
|
-
color = Color.new("hsla(225, 73%, 57%, 0.5)")
|
38
|
+
it "should initialize color by hsla string" do
|
39
|
+
color = Color.new("hsla(225, 73%, 57%, 0.5)")
|
40
40
|
expect(color.rgb).to eq(r: 65, g: 105, b: 225)
|
41
41
|
expect(color.alpha).to eq 0.5
|
42
42
|
end
|
43
|
-
|
44
|
-
it "should initialize color by textual string" do
|
43
|
+
|
44
|
+
it "should initialize color by textual string" do
|
45
45
|
color = Color.new("royalblue")
|
46
46
|
expect(color.rgb).to eq(r: 65, g: 105, b: 225)
|
47
47
|
end
|
48
48
|
|
49
|
-
it "should initialize color by textual string case" do
|
49
|
+
it "should initialize color by textual string case" do
|
50
50
|
color = Color.new("RoyalBlue")
|
51
51
|
expect(color.rgb).to eq(r: 65, g: 105, b: 225)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
|
56
|
-
describe ".new" do
|
57
|
-
it "should initialize color by rgb" do
|
56
|
+
describe ".new" do
|
57
|
+
it "should initialize color by rgb" do
|
58
58
|
color = Color.new(r: 51, g: 102, b: 204)
|
59
59
|
expect(color.rgb).to eq(r: 51, g: 102, b: 204)
|
60
60
|
end
|
61
61
|
|
62
|
-
it "should initialize color by rgba" do
|
62
|
+
it "should initialize color by rgba" do
|
63
63
|
color = Color.new(r: 51, g: 102, b: 204, a: 0.5)
|
64
64
|
expect(color.rgb).to eq(r: 51, g: 102, b: 204)
|
65
65
|
expect(color.alpha).to eq 0.5
|
66
66
|
end
|
67
67
|
|
68
|
-
it "should initialize color by hsl" do
|
68
|
+
it "should initialize color by hsl" do
|
69
69
|
color = Color.new(h: 225, s: 73, l: 57)
|
70
70
|
expect(color.rgb).to eq(r: 65, g: 105, b: 225)
|
71
71
|
end
|
72
72
|
|
73
|
-
it "should initialize color by hsla" do
|
73
|
+
it "should initialize color by hsla" do
|
74
74
|
color = Color.new(h: 225, s: 73, l: 57, a: 0.5)
|
75
75
|
expect(color.rgb).to eq(r: 65, g: 105, b: 225)
|
76
76
|
expect(color.alpha).to eq 0.5
|
77
77
|
end
|
78
|
-
|
79
|
-
it "should initialize color by hsv" do
|
78
|
+
|
79
|
+
it "should initialize color by hsv" do
|
80
80
|
color = Color.new(h: 220, s: 75, v: 80)
|
81
81
|
expect(color.rgb).to eq(r: 51, g: 102, b: 204)
|
82
82
|
end
|
83
83
|
|
84
|
-
it "should initialize color by hsb" do
|
84
|
+
it "should initialize color by hsb" do
|
85
85
|
color = Color.new(h: 220, s: 75, b: 80)
|
86
86
|
expect(color.rgb).to eq(r: 51, g: 102, b: 204)
|
87
87
|
end
|
88
88
|
|
89
|
-
it "should initialize color by cmyk" do
|
89
|
+
it "should initialize color by cmyk" do
|
90
90
|
color = Color.new(c: 74, m: 58, y: 22, k: 3)
|
91
91
|
expect(color.rgb).to eq(r: 64, g: 104, b: 193)
|
92
92
|
end
|
93
93
|
end
|
94
|
+
|
95
|
+
describe ".==" do
|
96
|
+
it "should be equal when same color" do
|
97
|
+
color_1 = Color.new("#3366cc")
|
98
|
+
color_2 = Color.new("#3366cc")
|
99
|
+
|
100
|
+
expect(color_1).to eq(color_2)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should be equal when logically same color" do
|
104
|
+
color_1 = Color.new("#3366cc")
|
105
|
+
color_2 = Color.new(r: 51, g: 102, b: 204)
|
106
|
+
|
107
|
+
expect(color_1).to eq(color_2)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should be equal when same color and alpha" do
|
111
|
+
color_1 = Color.new(r: 51, g: 102, b: 204, a: 0.2)
|
112
|
+
color_2 = Color.new("rgba(51, 102, 204, 0.2)")
|
113
|
+
|
114
|
+
expect(color_1).to eq(color_2)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should not be equal when same color but not same alpha" do
|
118
|
+
color_1 = Color.new(r: 51, g: 102, b: 204, a: 0.2)
|
119
|
+
color_2 = Color.new(r: 51, g: 102, b: 204, a: 0.2)
|
120
|
+
|
121
|
+
expect(color_1).to eq(color_2)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should not be equal when not same object" do
|
125
|
+
color_1 = Color.new(r: 51, g: 102, b: 204, a: 0.4)
|
126
|
+
color_like = Struct.new(:r, :g, :b, :alpha, keyword_init: true) do
|
127
|
+
def rgb
|
128
|
+
{r: r, g: g, b: b}
|
129
|
+
end
|
130
|
+
end
|
131
|
+
color_2 = color_like.new(r: 51, g: 102, b: 204, alpha: 0.4)
|
132
|
+
|
133
|
+
expect(color_1).not_to eq(color_2)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should not be equal when other is nil" do
|
137
|
+
color_1 = Color.new(r: 51, g: 102, b: 204, a: 0.4)
|
138
|
+
|
139
|
+
expect(color_1).not_to eq(nil)
|
140
|
+
end
|
141
|
+
end
|
94
142
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: color_conversion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek DeVries
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
|
-
rubygems_version: 3.
|
143
|
+
rubygems_version: 3.3.7
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: Convert colors to hex/rgb/hsv
|