decolmor 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -0
- data/NEWS.md +21 -0
- data/README.md +72 -22
- data/decolmor.gemspec +4 -4
- data/lib/decolmor/main.rb +246 -220
- data/lib/decolmor/version.rb +1 -1
- data/lib/decolmor.rb +0 -14
- data/spec/decolmor_spec.rb +137 -74
- data/spec/factories/alpha.rb +1 -1
- metadata +7 -7
data/spec/decolmor_spec.rb
CHANGED
@@ -1,7 +1,20 @@
|
|
1
1
|
load_class(__FILE__)
|
2
2
|
|
3
3
|
RSpec.describe Decolmor do
|
4
|
-
|
4
|
+
|
5
|
+
describe 'we can include the module into the class' do
|
6
|
+
let(:dummy_class) { Class.new { include Decolmor } }
|
7
|
+
|
8
|
+
it "class contains the module Decolmor" do
|
9
|
+
expect( dummy_class.include?(Decolmor) ).to eq true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "methods will be available into our class as class methods" do
|
13
|
+
expect { dummy_class.hsx_round = 3 }.to change { dummy_class.hsx_round }.from(1).to(3)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'we can set rounding globally for convert to HSL/HSV/HSB/CMYK' do
|
5
18
|
after(:each) do
|
6
19
|
Decolmor.hsx_round = 1
|
7
20
|
end
|
@@ -9,15 +22,14 @@ RSpec.describe Decolmor do
|
|
9
22
|
let(:colors) { FactoryBot.build(:colors_map, round: 2) }
|
10
23
|
|
11
24
|
it ".hsx_round by default 1" do
|
12
|
-
expect( Decolmor
|
25
|
+
expect( Decolmor.hsx_round ).to eq 1
|
13
26
|
end
|
14
27
|
|
15
28
|
it ".hsx_round= changes hsx_round" do
|
16
|
-
expect { Decolmor
|
29
|
+
expect { Decolmor.hsx_round = 2 }.to change { Decolmor.hsx_round }.from(1).to(2)
|
17
30
|
end
|
18
31
|
end
|
19
32
|
|
20
|
-
|
21
33
|
context 'HEX <==> RGB(A)' do
|
22
34
|
describe ".hex_to_rgb" do
|
23
35
|
let(:colors) { FactoryBot.build(:colors_map) }
|
@@ -25,24 +37,42 @@ RSpec.describe Decolmor do
|
|
25
37
|
|
26
38
|
it "HEX w prefix # to RGB" do
|
27
39
|
colors.each_pair do |hex, values|
|
28
|
-
expect( Decolmor
|
40
|
+
expect( Decolmor.hex_to_rgb(hex) ).to eq values[:rgb]
|
29
41
|
end
|
30
42
|
end
|
31
43
|
|
32
44
|
it "HEX w/o prefix # to RGB" do
|
33
45
|
colors.each_pair do |hex, values|
|
34
46
|
hex = hex.delete('#')
|
35
|
-
expect( Decolmor
|
47
|
+
expect( Decolmor.hex_to_rgb(hex) ).to eq values[:rgb]
|
36
48
|
end
|
37
49
|
end
|
38
50
|
|
39
51
|
it "HEX w alpha channel and prefix # to RGBA" do
|
40
|
-
docs "alpha into range 0..1 and rounding
|
52
|
+
docs "alpha into range 0..1 and rounding 3"
|
41
53
|
color = colors.keys.sample
|
42
54
|
alphas.each_pair do |hex_alpha, alpha|
|
43
55
|
hex = format('%s%s', color, hex_alpha)
|
44
56
|
rgba = colors[color][:rgb] + [alpha[:rgb]]
|
45
|
-
expect( Decolmor
|
57
|
+
expect( Decolmor.hex_to_rgb(hex) ).to eq rgba
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "set rounding for alpha channel" do
|
62
|
+
color = colors.keys.sample
|
63
|
+
alphas.each_pair do |hex_alpha, alpha|
|
64
|
+
rounding = 2
|
65
|
+
hex = format('%s%s', color, hex_alpha)
|
66
|
+
rgba = colors[color][:rgb] + [alpha[:rgb].round(rounding)]
|
67
|
+
expect( Decolmor.hex_to_rgb(hex, rounding) ).to eq rgba
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "set range 0..255 for alpha channel" do
|
72
|
+
color = colors.keys.sample
|
73
|
+
alphas.each_pair do |hex_alpha, alpha|
|
74
|
+
hex = format('%s%s', color, hex_alpha)
|
75
|
+
expect( Decolmor.hex_to_rgb(hex, alpha_255: true).last ).to eq alpha[:rgb_255]
|
46
76
|
end
|
47
77
|
end
|
48
78
|
|
@@ -52,7 +82,15 @@ RSpec.describe Decolmor do
|
|
52
82
|
alphas.each_pair do |hex_alpha, alpha|
|
53
83
|
hex = format('%s%s', color, hex_alpha).delete('#')
|
54
84
|
rgba = colors[color][:rgb] + [alpha[:rgb]]
|
55
|
-
expect( Decolmor
|
85
|
+
expect( Decolmor.hex_to_rgb(hex) ).to eq rgba
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it "HEX short version to RGB(A)" do
|
90
|
+
colors = {'6FC' => [102, 255, 204], '#9C3' => [153, 204, 51], '36FF' => [51, 102, 255, 1]}
|
91
|
+
|
92
|
+
colors.each_pair do |hex_short, rgb|
|
93
|
+
expect( Decolmor.hex_to_rgb(hex_short) ).to eq rgb
|
56
94
|
end
|
57
95
|
end
|
58
96
|
end
|
@@ -63,17 +101,27 @@ RSpec.describe Decolmor do
|
|
63
101
|
|
64
102
|
it "RGB converts to HEX" do
|
65
103
|
colors.each_pair do |hex, values|
|
66
|
-
expect( Decolmor
|
104
|
+
expect( Decolmor.rgb_to_hex(values[:rgb]) ).to eq hex
|
67
105
|
end
|
68
106
|
end
|
69
107
|
|
70
108
|
it "RGBA converts to HEX w alpha" do
|
71
109
|
color = colors.keys.sample
|
72
110
|
|
73
|
-
alphas.each_pair do |
|
74
|
-
hex = format('%s%s', color,
|
111
|
+
alphas.each_pair do |hex_alpha, alpha|
|
112
|
+
hex = format('%s%s', color, hex_alpha)
|
75
113
|
rgba = colors[color][:rgb] + [alpha[:rgb]]
|
76
|
-
expect( Decolmor
|
114
|
+
expect( Decolmor.rgb_to_hex(rgba) ).to eq hex
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
it "set range 0..255 for alpha channel" do
|
119
|
+
color = colors.keys.sample
|
120
|
+
|
121
|
+
alphas.each_pair do |hex_alpha, alpha|
|
122
|
+
hex = format('%s%s', color, hex_alpha)
|
123
|
+
rgba = colors[color][:rgb] + [alpha[:rgb_255]]
|
124
|
+
expect( Decolmor.rgb_to_hex(rgba, alpha_255: true) ).to eq hex
|
77
125
|
end
|
78
126
|
end
|
79
127
|
end
|
@@ -84,7 +132,7 @@ RSpec.describe Decolmor do
|
|
84
132
|
describe ".new_rgb" do
|
85
133
|
it "generate RGB with values into range 0..255" do
|
86
134
|
100.times do
|
87
|
-
expect( Decolmor
|
135
|
+
expect( Decolmor.new_rgb ).to all( be_between(0, 255) )
|
88
136
|
end
|
89
137
|
end
|
90
138
|
|
@@ -93,10 +141,10 @@ RSpec.describe Decolmor do
|
|
93
141
|
color = {red: 72, green: 209, blue: 204, alpha: 244}
|
94
142
|
# set and check each channel separately
|
95
143
|
color.each_with_index do |(key, value), index|
|
96
|
-
expect( Decolmor
|
144
|
+
expect( Decolmor.new_rgb(**{key => value})[index] ).to eq value
|
97
145
|
end
|
98
146
|
# set all channels
|
99
|
-
expect( Decolmor
|
147
|
+
expect( Decolmor.new_rgb(**color) ).to eq color.values
|
100
148
|
end
|
101
149
|
end
|
102
150
|
end
|
@@ -109,32 +157,32 @@ RSpec.describe Decolmor do
|
|
109
157
|
|
110
158
|
it "RGB converts to HSL" do
|
111
159
|
colors.each_pair do |hex, values|
|
112
|
-
expect( Decolmor
|
160
|
+
expect( Decolmor.rgb_to_hsl(values[:rgb]) ).to eq values[:hsl]
|
113
161
|
end
|
114
162
|
end
|
115
163
|
|
116
164
|
it "alpha channel pass to HSL unchanged" do
|
117
165
|
color = colors.keys.sample
|
118
|
-
alphas.each_pair do |
|
166
|
+
alphas.each_pair do |_hex_alpha, alpha|
|
119
167
|
rgba = colors[color][:rgb] + [alpha[:rgb]]
|
120
|
-
expect( Decolmor
|
168
|
+
expect( Decolmor.rgb_to_hsl(rgba).last ).to eq alpha[:rgb]
|
121
169
|
end
|
122
170
|
end
|
123
171
|
|
124
172
|
it "you can set rounding for resulting HSL values (default = 1)" do
|
125
173
|
docs "round 1 enough for a lossless conversion RGB -> HSL/HSV/HSB -> RGB"
|
126
174
|
colors.each_pair do |hex, values|
|
127
|
-
expect( Decolmor
|
175
|
+
expect( Decolmor.rgb_to_hsl(values[:rgb], 0) ).to eq values[:hsl].map(&:round)
|
128
176
|
end
|
129
177
|
end
|
130
178
|
|
131
179
|
it "setting rounding doesn't affect alpha channel" do
|
132
180
|
color = colors.keys.sample
|
133
|
-
alphas.each_pair do |
|
181
|
+
alphas.each_pair do |_hex_alpha, alpha|
|
134
182
|
rgba = colors[color][:rgb] + [alpha[:rgb]]
|
135
183
|
# alpha shouldn't be rounded because its range is 0..1
|
136
184
|
# if that did happen, we would get 0 or 1 instead of the normal value
|
137
|
-
expect( Decolmor
|
185
|
+
expect( Decolmor.rgb_to_hsl(rgba, 0).last ).to eq alpha[:rgb]
|
138
186
|
end
|
139
187
|
end
|
140
188
|
end
|
@@ -146,36 +194,36 @@ RSpec.describe Decolmor do
|
|
146
194
|
|
147
195
|
it "RGB converts to HSV" do
|
148
196
|
colors.each_pair do |hex, values|
|
149
|
-
expect( Decolmor
|
197
|
+
expect( Decolmor.rgb_to_hsv(values[:rgb]) ).to eq values[:hsv]
|
150
198
|
end
|
151
199
|
end
|
152
200
|
|
153
201
|
it "alpha channel pass to HSV unchanged" do
|
154
202
|
color = colors.keys.sample
|
155
|
-
alphas.each_pair do |
|
203
|
+
alphas.each_pair do |_hex_alpha, alpha|
|
156
204
|
rgba = colors[color][:rgb] + [alpha[:rgb]]
|
157
|
-
expect( Decolmor
|
205
|
+
expect( Decolmor.rgb_to_hsv(rgba).last ).to eq alpha[:rgb]
|
158
206
|
end
|
159
207
|
end
|
160
208
|
|
161
209
|
it "you can set rounding for resulting HSV values (default = 1)" do
|
162
210
|
colors_round_2.each_pair do |hex, values|
|
163
|
-
expect( Decolmor
|
211
|
+
expect( Decolmor.rgb_to_hsv(values[:rgb], 0) ).to eq values[:hsv].map(&:round)
|
164
212
|
end
|
165
213
|
end
|
166
214
|
|
167
215
|
it "setting rounding doesn't affect alpha channel" do
|
168
216
|
color = colors.keys.sample
|
169
|
-
alphas.each_pair do |
|
217
|
+
alphas.each_pair do |_hex_alpha, alpha|
|
170
218
|
rgba = colors[color][:rgb] + [alpha[:rgb]]
|
171
|
-
expect( Decolmor
|
219
|
+
expect( Decolmor.rgb_to_hsv(rgba, 0).last ).to eq alpha[:rgb]
|
172
220
|
end
|
173
221
|
end
|
174
222
|
end
|
175
223
|
|
176
224
|
describe ".rgb_to_hsb" do
|
177
225
|
it "alias .rgb_to_hsv" do
|
178
|
-
expect(
|
226
|
+
expect( Decolmor.method(:rgb_to_hsb ).original_name).to eq(:rgb_to_hsv)
|
179
227
|
end
|
180
228
|
end
|
181
229
|
end
|
@@ -187,16 +235,16 @@ RSpec.describe Decolmor do
|
|
187
235
|
let(:alphas) { FactoryBot.build(:alpha) }
|
188
236
|
|
189
237
|
it "HSL converts to RGB" do
|
190
|
-
colors.each_pair do |
|
191
|
-
expect( Decolmor
|
238
|
+
colors.each_pair do |_hex, values|
|
239
|
+
expect( Decolmor.hsl_to_rgb(values[:hsl]) ).to eq values[:rgb]
|
192
240
|
end
|
193
241
|
end
|
194
242
|
|
195
243
|
it "alpha channel pass to RGB unchanged" do
|
196
244
|
color = colors.keys.sample
|
197
|
-
alphas.each_pair do |
|
245
|
+
alphas.each_pair do |_hex_alpha, values|
|
198
246
|
hsla = colors[color][:hsl] + [values[:rgb]]
|
199
|
-
expect( Decolmor
|
247
|
+
expect( Decolmor.hsl_to_rgb(hsla).last ).to eq values[:rgb]
|
200
248
|
end
|
201
249
|
end
|
202
250
|
end
|
@@ -206,23 +254,23 @@ RSpec.describe Decolmor do
|
|
206
254
|
let(:alphas) { FactoryBot.build(:alpha) }
|
207
255
|
|
208
256
|
it "HSV converts to RGB" do
|
209
|
-
colors.each_pair do |
|
210
|
-
expect( Decolmor
|
257
|
+
colors.each_pair do |_hex, values|
|
258
|
+
expect( Decolmor.hsv_to_rgb(values[:hsv]) ).to eq values[:rgb]
|
211
259
|
end
|
212
260
|
end
|
213
261
|
|
214
262
|
it "alpha channel pass to RGB unchanged" do
|
215
263
|
color = colors.keys.sample
|
216
|
-
alphas.each_pair do |
|
264
|
+
alphas.each_pair do |_hex_alpha, values|
|
217
265
|
hsva = colors[color][:hsv] + [values[:rgb]]
|
218
|
-
expect( Decolmor
|
266
|
+
expect( Decolmor.hsv_to_rgb(hsva).last ).to eq values[:rgb]
|
219
267
|
end
|
220
268
|
end
|
221
269
|
end
|
222
270
|
|
223
271
|
describe ".hsb_to_rgb" do
|
224
272
|
it "alias .hsv_to_rgb" do
|
225
|
-
expect(
|
273
|
+
expect( Decolmor.method(:hsb_to_rgb ).original_name).to eq(:hsv_to_rgb)
|
226
274
|
end
|
227
275
|
end
|
228
276
|
end
|
@@ -234,16 +282,24 @@ RSpec.describe Decolmor do
|
|
234
282
|
let(:alphas) { FactoryBot.build(:alpha) }
|
235
283
|
|
236
284
|
it "HSL converts to RGB" do
|
237
|
-
colors.each_pair do |
|
238
|
-
expect( Decolmor
|
285
|
+
colors.each_pair do |_hex, values|
|
286
|
+
expect( Decolmor.hsl_to_rgb_alt(values[:hsl]) ).to eq values[:rgb]
|
239
287
|
end
|
240
288
|
end
|
241
289
|
|
242
290
|
it "alpha channel pass to RGB unchanged" do
|
243
291
|
color = colors.keys.sample
|
244
|
-
alphas.each_pair do |
|
292
|
+
alphas.each_pair do |_hex_alpha, values|
|
245
293
|
hsla = colors[color][:hsl] + [values[:rgb]]
|
246
|
-
expect( Decolmor
|
294
|
+
expect( Decolmor.hsl_to_rgb_alt(hsla).last ).to eq values[:rgb]
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
it "if hue not a range member 0..360 return identical RGB values (colorless)" do
|
299
|
+
colors.each_pair do |hex, values|
|
300
|
+
hsl = values[:hsl]
|
301
|
+
hsl[0] += 360
|
302
|
+
expect( Decolmor.hsl_to_rgb_alt(hsl).uniq.size ).to eq 1
|
247
303
|
end
|
248
304
|
end
|
249
305
|
end
|
@@ -253,23 +309,31 @@ RSpec.describe Decolmor do
|
|
253
309
|
let(:alphas) { FactoryBot.build(:alpha) }
|
254
310
|
|
255
311
|
it "HSV converts to RGB" do
|
256
|
-
colors.each_pair do |
|
257
|
-
expect( Decolmor
|
312
|
+
colors.each_pair do |_hex, values|
|
313
|
+
expect( Decolmor.hsv_to_rgb_alt(values[:hsv]) ).to eq values[:rgb]
|
258
314
|
end
|
259
315
|
end
|
260
316
|
|
261
317
|
it "alpha channel pass to RGB unchanged" do
|
262
318
|
color = colors.keys.sample
|
263
|
-
alphas.each_pair do |
|
319
|
+
alphas.each_pair do |_hex_alpha, values|
|
264
320
|
hsva = colors[color][:hsv] + [values[:rgb]]
|
265
|
-
expect( Decolmor
|
321
|
+
expect( Decolmor.hsv_to_rgb_alt(hsva).last ).to eq values[:rgb]
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
it "if hue not a range member 0..360 return identical RGB values (colorless)" do
|
326
|
+
colors.each_pair do |_hex, values|
|
327
|
+
hsl = values[:hsl]
|
328
|
+
hsl[0] -= 360
|
329
|
+
expect( Decolmor.hsl_to_rgb_alt(hsl).uniq.size ).to eq 1
|
266
330
|
end
|
267
331
|
end
|
268
332
|
end
|
269
333
|
|
270
334
|
describe ".hsb_to_rgb_alt" do
|
271
335
|
it "alias .hsv_to_rgb_alt" do
|
272
|
-
expect(
|
336
|
+
expect( Decolmor.method(:hsb_to_rgb_alt ).original_name).to eq(:hsv_to_rgb_alt)
|
273
337
|
end
|
274
338
|
end
|
275
339
|
end
|
@@ -284,36 +348,36 @@ RSpec.describe Decolmor do
|
|
284
348
|
it "HSL converts to HSV" do
|
285
349
|
colors.each_pair do |hex_, values|
|
286
350
|
hsv = values[:hsv].map { |value| value.round(1) }
|
287
|
-
expect( Decolmor
|
351
|
+
expect( Decolmor.hsl_to_hsv(values[:hsl]) ).to eq hsv
|
288
352
|
end
|
289
353
|
end
|
290
354
|
|
291
355
|
it "alpha channel pass to HSV unchanged" do
|
292
356
|
color = colors.keys.sample
|
293
|
-
alphas.each_pair do |
|
357
|
+
alphas.each_pair do |_hex_alpha, alpha|
|
294
358
|
hsla = colors[color][:hsl] + [alpha[:rgb]]
|
295
|
-
expect( Decolmor
|
359
|
+
expect( Decolmor.hsl_to_hsv(hsla).last ).to eq alpha[:rgb]
|
296
360
|
end
|
297
361
|
end
|
298
362
|
|
299
363
|
it "you can set rounding for resulting HSV values (default = 1)" do
|
300
|
-
colors.each_pair do |
|
301
|
-
expect( Decolmor
|
364
|
+
colors.each_pair do |_hex, values|
|
365
|
+
expect( Decolmor.hsl_to_hsv(values[:hsl], 0) ).to eq values[:hsv].map(&:round)
|
302
366
|
end
|
303
367
|
end
|
304
368
|
|
305
369
|
it "setting rounding doesn't affect alpha channel" do
|
306
370
|
color = colors.keys.sample
|
307
|
-
alphas.each_pair do |
|
371
|
+
alphas.each_pair do |_hex_alpha, alpha|
|
308
372
|
hsla = colors[color][:hsl] + [alpha[:rgb]]
|
309
|
-
expect( Decolmor
|
373
|
+
expect( Decolmor.hsl_to_hsv(hsla, 0).last ).to eq alpha[:rgb]
|
310
374
|
end
|
311
375
|
end
|
312
376
|
end
|
313
377
|
|
314
378
|
describe ".hsl_to_hsb" do
|
315
379
|
it "alias .hsl_to_hsv" do
|
316
|
-
expect(
|
380
|
+
expect( Decolmor.method(:hsl_to_hsb).original_name ).to eq(:hsl_to_hsv)
|
317
381
|
end
|
318
382
|
end
|
319
383
|
|
@@ -323,38 +387,38 @@ RSpec.describe Decolmor do
|
|
323
387
|
let(:alphas) { FactoryBot.build(:alpha) }
|
324
388
|
|
325
389
|
it "HSV converts to HSL" do
|
326
|
-
colors.each_pair do |
|
390
|
+
colors.each_pair do |_hex, values|
|
327
391
|
hsl = values[:hsl].map { |value| value.round(1) }
|
328
|
-
expect( Decolmor
|
392
|
+
expect( Decolmor.hsv_to_hsl(values[:hsv]) ).to eq hsl
|
329
393
|
end
|
330
394
|
end
|
331
395
|
|
332
396
|
it "alpha channel pass to HSL unchanged" do
|
333
397
|
color = colors.keys.sample
|
334
|
-
alphas.each_pair do |
|
398
|
+
alphas.each_pair do |_hex_alpha, alpha|
|
335
399
|
hsva = colors[color][:hsv] + [alpha[:rgb]]
|
336
|
-
expect( Decolmor
|
400
|
+
expect( Decolmor.hsv_to_hsl(hsva).last ).to eq alpha[:rgb]
|
337
401
|
end
|
338
402
|
end
|
339
403
|
|
340
404
|
it "you can set rounding for resulting HSL values (default = 1)" do
|
341
|
-
colors.each_pair do |
|
342
|
-
expect( Decolmor
|
405
|
+
colors.each_pair do |_hex, values|
|
406
|
+
expect( Decolmor.hsv_to_hsl(values[:hsv], 0) ).to eq values[:hsl].map(&:round)
|
343
407
|
end
|
344
408
|
end
|
345
409
|
|
346
410
|
it "setting rounding doesn't affect alpha channel" do
|
347
411
|
color = colors.keys.sample
|
348
|
-
alphas.each_pair do |
|
412
|
+
alphas.each_pair do |_hex, alpha|
|
349
413
|
hsva = colors[color][:hsv] + [alpha[:rgb]]
|
350
|
-
expect( Decolmor
|
414
|
+
expect( Decolmor.hsv_to_hsl(hsva, 0).last ).to eq alpha[:rgb]
|
351
415
|
end
|
352
416
|
end
|
353
417
|
end
|
354
418
|
|
355
419
|
describe ".hsb_to_hsl" do
|
356
420
|
it "alias .hsv_to_hsl" do
|
357
|
-
expect(
|
421
|
+
expect( Decolmor.method(:hsb_to_hsl).original_name ).to eq(:hsv_to_hsl)
|
358
422
|
end
|
359
423
|
end
|
360
424
|
end
|
@@ -369,29 +433,29 @@ RSpec.describe Decolmor do
|
|
369
433
|
colors.each_pair do |hex_, values|
|
370
434
|
|
371
435
|
cmyk = values[:cmyk].map {|arr| arr.round(1) }
|
372
|
-
expect( Decolmor
|
436
|
+
expect( Decolmor.rgb_to_cmyk(values[:rgb]) ).to eq cmyk
|
373
437
|
end
|
374
438
|
end
|
375
439
|
|
376
440
|
it "alpha channel pass to HSL unchanged" do
|
377
441
|
color = colors.keys.sample
|
378
|
-
alphas.each_pair do |
|
442
|
+
alphas.each_pair do |_hex_alpha, alpha|
|
379
443
|
rgba = colors[color][:rgb] + [alpha[:rgb]]
|
380
|
-
expect( Decolmor
|
444
|
+
expect( Decolmor.rgb_to_cmyk(rgba).last ).to eq alpha[:rgb]
|
381
445
|
end
|
382
446
|
end
|
383
447
|
|
384
448
|
it "you can set rounding for resulting CMYK values (default = 1)" do
|
385
449
|
colors.each_pair do |hex, values|
|
386
|
-
expect( Decolmor
|
450
|
+
expect( Decolmor.hsv_to_hsl(values[:hsv], 0) ).to eq values[:hsl].map(&:round)
|
387
451
|
end
|
388
452
|
end
|
389
453
|
|
390
454
|
it "setting rounding doesn't affect alpha channel" do
|
391
455
|
color = colors.keys.sample
|
392
|
-
alphas.each_pair do |
|
456
|
+
alphas.each_pair do |_hex_alpha, alpha|
|
393
457
|
rgba = colors[color][:rgb] + [alpha[:rgb]]
|
394
|
-
expect( Decolmor
|
458
|
+
expect( Decolmor.rgb_to_cmyk(rgba, 0).last ).to eq alpha[:rgb]
|
395
459
|
end
|
396
460
|
end
|
397
461
|
end
|
@@ -402,19 +466,18 @@ RSpec.describe Decolmor do
|
|
402
466
|
|
403
467
|
it "CMYK converts to RGB" do
|
404
468
|
colors.each_pair do |hex_, values|
|
405
|
-
expect( Decolmor
|
469
|
+
expect( Decolmor.cmyk_to_rgb(values[:cmyk]) ).to eq values[:rgb]
|
406
470
|
end
|
407
471
|
end
|
408
472
|
|
409
473
|
it "alpha channel pass to RGB unchanged" do
|
410
474
|
color = colors.keys.sample
|
411
|
-
alphas.each_pair do |
|
475
|
+
alphas.each_pair do |_hex_alpha, values|
|
412
476
|
cmyka = colors[color][:cmyk] + [values[:rgb]]
|
413
|
-
expect( Decolmor
|
477
|
+
expect( Decolmor.cmyk_to_rgb(cmyka).last ).to eq values[:rgb]
|
414
478
|
end
|
415
479
|
end
|
416
480
|
end
|
417
481
|
end
|
418
482
|
|
419
483
|
end
|
420
|
-
|
data/spec/factories/alpha.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decolmor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ChildrenofkoRn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,7 +93,7 @@ dependencies:
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '7.0'
|
95
95
|
description: |-
|
96
|
-
|
96
|
+
Converter color spaces from/to: HEX/RGB/HSL/HSV/HSB/CMYK.
|
97
97
|
The Alpha channel (transparency) is supported.
|
98
98
|
There is also a simple RGB generator.
|
99
99
|
email: Rick-ROR@ya.ru
|
@@ -123,9 +123,9 @@ licenses:
|
|
123
123
|
- MIT
|
124
124
|
metadata:
|
125
125
|
homepage_uri: https://github.com/ChildrenofkoRn/decolmor
|
126
|
-
news_uri: https://github.com/ChildrenofkoRn/decolmor/blob/
|
127
|
-
changelog_uri: https://github.com/ChildrenofkoRn/decolmor/blob/
|
128
|
-
documentation_uri: https://github.com/ChildrenofkoRn/decolmor/blob/
|
126
|
+
news_uri: https://github.com/ChildrenofkoRn/decolmor/blob/main/NEWS.md
|
127
|
+
changelog_uri: https://github.com/ChildrenofkoRn/decolmor/blob/main/CHANGELOG.md
|
128
|
+
documentation_uri: https://github.com/ChildrenofkoRn/decolmor/blob/main/README.md
|
129
129
|
bug_tracker_uri: https://github.com/ChildrenofkoRn/decolmor/issues
|
130
130
|
source_code_uri: https://github.com/ChildrenofkoRn/decolmor
|
131
131
|
post_install_message:
|
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
146
|
+
rubygems_version: 3.2.27
|
147
147
|
signing_key:
|
148
148
|
specification_version: 4
|
149
149
|
summary: 'Converter color spaces from/to: HEX/RGB/HSL/HSV/HSB/CMYK'
|