colorable 0.1.4 → 0.2.0
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/README.md +123 -93
- data/lib/colorable.rb +6 -2
- data/lib/colorable/color.rb +87 -24
- data/lib/colorable/color_space.rb +250 -205
- data/lib/colorable/colorset.rb +4 -4
- data/lib/colorable/version.rb +1 -1
- data/spec/color_space_spec.rb +99 -27
- data/spec/color_spec.rb +124 -40
- data/spec/colorable_spec.rb +63 -49
- data/spec/colorset_spec.rb +2 -2
- metadata +2 -2
data/lib/colorable/colorset.rb
CHANGED
@@ -62,7 +62,7 @@ module Colorable
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def to_s
|
65
|
-
"#<%s %d/%d pos='%s
|
65
|
+
"#<%s %d/%d pos='%s<%s/%s>'>" % [self.class, @pos, size, at.name, at._rgb, at._hsb]
|
66
66
|
end
|
67
67
|
alias :inspect :to_s
|
68
68
|
|
@@ -90,11 +90,11 @@ module Colorable
|
|
90
90
|
order_cond =
|
91
91
|
case order
|
92
92
|
when *rgb_part
|
93
|
-
->color{ color.
|
93
|
+
->color{ color._rgb.move_to_top rgb_part.index(order) }
|
94
94
|
when *hsb_part
|
95
|
-
->color{ color.
|
95
|
+
->color{ color._hsb.move_to_top hsb_part.index(order) }
|
96
96
|
when :name, :rgb, :hsb, :hsv, :hex
|
97
|
-
->color{ color.send order }
|
97
|
+
->color{ color.send "_#{order}" }
|
98
98
|
end
|
99
99
|
|
100
100
|
case opt[:dir].intern
|
data/lib/colorable/version.rb
CHANGED
data/spec/color_space_spec.rb
CHANGED
@@ -35,28 +35,45 @@ describe RGB do
|
|
35
35
|
before(:all) { @rgb = RGB.new(100, 100, 100) }
|
36
36
|
subject { @rgb + [0, 50, 100] }
|
37
37
|
its(:rgb) { should eql [100, 150, 200] }
|
38
|
-
it "keep original same" do
|
38
|
+
it "keep original same" do
|
39
|
+
@rgb.rgb.should eql [100, 100, 100]
|
40
|
+
end
|
39
41
|
end
|
40
42
|
|
41
43
|
context "when '+' makes out of RGB range or rack of numbers" do
|
42
44
|
it "raise ArgumentError" do
|
43
|
-
expect { RGB.new(100, 100, 100) + [0, 50, 200] }.to raise_error ArgumentError
|
44
|
-
expect { RGB.new(100, 100, 100) + [0, -150, 0] }.to raise_error ArgumentError
|
45
45
|
expect { RGB.new(100, 100, 100) + [0, 150] }.to raise_error ArgumentError
|
46
46
|
end
|
47
|
+
|
48
|
+
it "not raise ArgumentError" do
|
49
|
+
expect { RGB.new(100, 100, 100) + [0, 50, 200] }.not_to raise_error ArgumentError
|
50
|
+
expect { RGB.new(100, 100, 100) + [0, -150, 0] }.not_to raise_error ArgumentError
|
51
|
+
end
|
47
52
|
end
|
48
53
|
|
49
54
|
context "pass a Fixnum" do
|
50
55
|
before(:all) { @rgb = RGB.new(100, 100, 100) }
|
51
56
|
it { (@rgb + 50).rgb.should eql [150, 150, 150] }
|
52
|
-
it "raise ArgumentError" do
|
53
|
-
expect { @rgb + 160 }.
|
57
|
+
it "not raise ArgumentError" do
|
58
|
+
expect { @rgb + 160 }.not_to raise_error ArgumentError
|
54
59
|
end
|
55
60
|
end
|
56
61
|
|
57
62
|
context "coerce make Fixnum#+ accept rgb object" do
|
58
63
|
it { (10 + RGB.new(100, 100, 100)).rgb.should eql [110, 110, 110] }
|
59
64
|
end
|
65
|
+
|
66
|
+
context "pass a RGB object" do
|
67
|
+
before(:each) do
|
68
|
+
@a = RGB.new(100, 100, 255)
|
69
|
+
@b = RGB.new(255, 100, 100)
|
70
|
+
@c = RGB.new(100, 255, 100)
|
71
|
+
end
|
72
|
+
it { (@a + @b).rgb.should eql [255, 200, 255] }
|
73
|
+
it { (@b + @c).rgb.should eql [255, 255, 200] }
|
74
|
+
it { (@a + @c).rgb.should eql [200, 255, 255] }
|
75
|
+
it { (@a + @b + @c).rgb.should eql [255, 255, 255] }
|
76
|
+
end
|
60
77
|
end
|
61
78
|
|
62
79
|
describe "#-" do
|
@@ -64,22 +81,64 @@ describe RGB do
|
|
64
81
|
before(:all) { @rgb = RGB.new(100, 100, 100) }
|
65
82
|
subject { @rgb - [0, 50, 100] }
|
66
83
|
its(:rgb) { should eql [100, 50, 0] }
|
67
|
-
it "keep original same" do
|
84
|
+
it "keep original same" do
|
85
|
+
@rgb.rgb.should eql [100, 100, 100]
|
86
|
+
end
|
68
87
|
end
|
69
88
|
|
70
89
|
context "when '-' makes out of RGB range" do
|
71
|
-
it "raise ArgumentError" do
|
72
|
-
expect { RGB.new(100, 100, 100) - [0, 50, 200] }.
|
73
|
-
expect { RGB.new(100, 100, 100) - [0, -250, 0] }.
|
90
|
+
it "not raise ArgumentError" do
|
91
|
+
expect { RGB.new(100, 100, 100) - [0, 50, 200] }.not_to raise_error ArgumentError
|
92
|
+
expect { RGB.new(100, 100, 100) - [0, -250, 0] }.not_to raise_error ArgumentError
|
74
93
|
end
|
75
94
|
end
|
76
95
|
|
77
96
|
context "pass a Fixnum" do
|
78
97
|
before(:all) { @rgb = RGB.new(100, 100, 100) }
|
79
98
|
it { (@rgb - 50).rgb.should eql [50, 50, 50] }
|
80
|
-
it "raise ArgumentError" do
|
81
|
-
expect { @rgb - 160 }.
|
99
|
+
it "not raise ArgumentError" do
|
100
|
+
expect { @rgb - 160 }.not_to raise_error ArgumentError
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "pass a RGB object" do
|
105
|
+
before(:each) do
|
106
|
+
@a = RGB.new(100, 100, 255)
|
107
|
+
@b = RGB.new(255, 100, 100)
|
108
|
+
@c = RGB.new(100, 255, 100)
|
82
109
|
end
|
110
|
+
it { (@a - @b).rgb.should eql [100, 0, 100] }
|
111
|
+
it { (@b - @c).rgb.should eql [100, 100, 0] }
|
112
|
+
it { (@a - @c).rgb.should eql [0, 100, 100] }
|
113
|
+
it { (@a - @b - @c).rgb.should eql [0, 0, 0] }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "#*" do
|
118
|
+
context "pass a RGB object" do
|
119
|
+
before(:each) do
|
120
|
+
@a = RGB.new(100, 100, 255)
|
121
|
+
@b = RGB.new(255, 100, 100)
|
122
|
+
@c = RGB.new(100, 255, 100)
|
123
|
+
end
|
124
|
+
it { (@a * @b).rgb.should eql [100, 39, 100] }
|
125
|
+
it { (@b * @c).rgb.should eql [100, 100, 39] }
|
126
|
+
it { (@a * @c).rgb.should eql [39, 100, 100] }
|
127
|
+
it { (@a * @b * @c).rgb.should eql [39, 39, 39] }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "#/" do
|
132
|
+
context "pass a RGB object" do
|
133
|
+
before(:each) do
|
134
|
+
@a = RGB.new(100, 100, 255)
|
135
|
+
@b = RGB.new(255, 100, 100)
|
136
|
+
@c = RGB.new(100, 255, 100)
|
137
|
+
end
|
138
|
+
it { (@a / @b).rgb.should eql [255, 161, 255] }
|
139
|
+
it { (@b / @c).rgb.should eql [255, 255, 161] }
|
140
|
+
it { (@a / @c).rgb.should eql [161, 255, 255] }
|
141
|
+
it { (@a / @b / @c).rgb.should eql [255, 255, 255] }
|
83
142
|
end
|
84
143
|
end
|
85
144
|
|
@@ -139,11 +198,14 @@ describe HSB do
|
|
139
198
|
|
140
199
|
context "when '+' makes out of HSB range or rack of numbers" do
|
141
200
|
it "raise ArgumentError" do
|
142
|
-
expect { HSB.new(300, 70, 90) + [0, 50, 0] }.to raise_error ArgumentError
|
143
|
-
expect { HSB.new(300, 70, 90) + [0, 0, -100] }.to raise_error ArgumentError
|
144
201
|
expect { HSB.new(300, 70, 90) + [0, 5] }.to raise_error ArgumentError
|
145
202
|
expect { HSB.new(300, 70, 90) + 5 }.to raise_error ArgumentError
|
146
203
|
end
|
204
|
+
|
205
|
+
it "not raise ArgumentError" do
|
206
|
+
expect { HSB.new(300, 70, 90) + [60, 50, 0] }.not_to raise_error ArgumentError
|
207
|
+
expect { HSB.new(300, 70, 90) + [0, 0, -100] }.not_to raise_error ArgumentError
|
208
|
+
end
|
147
209
|
end
|
148
210
|
end
|
149
211
|
|
@@ -156,9 +218,9 @@ describe HSB do
|
|
156
218
|
end
|
157
219
|
|
158
220
|
context "when '-' makes out of HSB range" do
|
159
|
-
it "raise ArgumentError" do
|
160
|
-
expect { HSB.new(300, 7, 90) - [305, 0, 10] }.
|
161
|
-
expect { HSB.new(300, 70, 90) - [0, -35, 0] }.
|
221
|
+
it "not raise ArgumentError" do
|
222
|
+
expect { HSB.new(300, 7, 90) - [305, 0, 10] }.not_to raise_error ArgumentError
|
223
|
+
expect { HSB.new(300, 70, 90) - [0, -35, 0] }.not_to raise_error ArgumentError
|
162
224
|
end
|
163
225
|
end
|
164
226
|
end
|
@@ -283,12 +345,17 @@ describe HEX do
|
|
283
345
|
it { (@hex + '#00ffcc').hex.should eql '#FFFFCC'}
|
284
346
|
it { (@hex + '00FFCC').hex.should eql '#FFFFCC'}
|
285
347
|
it { (@hex + '#0FC').hex.should eql '#FFFFCC'}
|
286
|
-
it "keep original" do
|
348
|
+
it "keep original" do
|
349
|
+
@hex.hex.should eql '#FF0000'
|
350
|
+
end
|
287
351
|
end
|
288
352
|
|
289
|
-
context "out of HEX range" do
|
353
|
+
context "out of HEX range or Array" do
|
354
|
+
it "not raise ArgumentError" do
|
355
|
+
expect { HEX.new('#FF0000') + '#010000' }.not_to raise_error ArgumentError
|
356
|
+
end
|
357
|
+
|
290
358
|
it "raise ArgumentError" do
|
291
|
-
expect { HEX.new('#FF0000') + '#010000' }.to raise_error ArgumentError
|
292
359
|
expect { HEX.new('#FF0000') + '#00ffgg' }.to raise_error ArgumentError
|
293
360
|
expect { HEX.new('#000000') + [0, 50, 100] }.to raise_error ArgumentError
|
294
361
|
end
|
@@ -297,8 +364,8 @@ describe HEX do
|
|
297
364
|
context "pass a Fixnum" do
|
298
365
|
before(:all) { @hex = HEX.new('#000000') }
|
299
366
|
it { (@hex + 255).hex.should eql '#FFFFFF' }
|
300
|
-
it "raise ArgumentError" do
|
301
|
-
expect { @hex + 260 }.
|
367
|
+
it "not raise ArgumentError" do
|
368
|
+
expect { @hex + 260 }.not_to raise_error ArgumentError
|
302
369
|
end
|
303
370
|
end
|
304
371
|
|
@@ -314,13 +381,18 @@ describe HEX do
|
|
314
381
|
it { (@hex - '#00ffcc').hex.should eql '#000033'}
|
315
382
|
it { (@hex - '00FFCC').hex.should eql '#000033'}
|
316
383
|
it { (@hex - '#0FC').hex.should eql '#000033'}
|
317
|
-
it "keep original" do
|
384
|
+
it "keep original" do
|
385
|
+
@hex.hex.should eql '#00FFFF'
|
386
|
+
end
|
318
387
|
end
|
319
388
|
|
320
|
-
context "out of HEX range" do
|
389
|
+
context "out of HEX range or Array" do
|
390
|
+
it "not raise ArgumentError" do
|
391
|
+
expect { HEX.new('#FF0000') - '#000100' }.not_to raise_error ArgumentError
|
392
|
+
expect { HEX.new('#FF0000') - '#0000cc' }.not_to raise_error ArgumentError
|
393
|
+
end
|
394
|
+
|
321
395
|
it "raise ArgumentError" do
|
322
|
-
expect { HEX.new('#FF0000') - '#000100' }.to raise_error ArgumentError
|
323
|
-
expect { HEX.new('#FF0000') - '#0000cc' }.to raise_error ArgumentError
|
324
396
|
expect { HEX.new('#000000') - [0, 50, 100] }.to raise_error ArgumentError
|
325
397
|
end
|
326
398
|
end
|
@@ -328,8 +400,8 @@ describe HEX do
|
|
328
400
|
context "pass a Fixnum" do
|
329
401
|
before(:all) { @hex = HEX.new('#FFFFFF') }
|
330
402
|
it { (@hex - 255).hex.should eql '#000000' }
|
331
|
-
it "raise ArgumentError" do
|
332
|
-
expect { @hex + 260 }.
|
403
|
+
it "not raise ArgumentError" do
|
404
|
+
expect { @hex + 260 }.not_to raise_error ArgumentError
|
333
405
|
end
|
334
406
|
end
|
335
407
|
|
data/spec/color_spec.rb
CHANGED
@@ -5,19 +5,19 @@ describe Color do
|
|
5
5
|
describe ".new" do
|
6
6
|
context "with a string" do
|
7
7
|
context "of valid colorname" do
|
8
|
-
it { Color.new("Alice Blue").name.
|
9
|
-
it { Color.new("Khaki").name.
|
10
|
-
it { Color.new("Mint Cream").name.
|
11
|
-
it { Color.new("Thistle").name.
|
8
|
+
it { Color.new("Alice Blue").name.should eql "Alice Blue" }
|
9
|
+
it { Color.new("Khaki").name.should eql "Khaki" }
|
10
|
+
it { Color.new("Mint Cream").name.should eql "Mint Cream" }
|
11
|
+
it { Color.new("Thistle").name.should eql "Thistle" }
|
12
12
|
end
|
13
13
|
|
14
14
|
context "of valid name variations" do
|
15
|
-
it { Color.new("AliceBlue").name.
|
16
|
-
it { Color.new("aliceblue").name.
|
17
|
-
it { Color.new("aliceblue").name.
|
18
|
-
it { Color.new(:AliceBlue).name.
|
19
|
-
it { Color.new(:aliceblue).name.
|
20
|
-
it { Color.new(:alice_blue).name.
|
15
|
+
it { Color.new("AliceBlue").name.should eql "Alice Blue" }
|
16
|
+
it { Color.new("aliceblue").name.should eql "Alice Blue" }
|
17
|
+
it { Color.new("aliceblue").name.should eql "Alice Blue" }
|
18
|
+
it { Color.new(:AliceBlue).name.should eql "Alice Blue" }
|
19
|
+
it { Color.new(:aliceblue).name.should eql "Alice Blue" }
|
20
|
+
it { Color.new(:alice_blue).name.should eql "Alice Blue" }
|
21
21
|
end
|
22
22
|
|
23
23
|
context "of invalid name" do
|
@@ -30,9 +30,9 @@ describe Color do
|
|
30
30
|
|
31
31
|
context "with a HEX string" do
|
32
32
|
context "of valid HEX" do
|
33
|
-
it { Color.new("#FFFFFF").hex.
|
34
|
-
it { Color.new("#00F").hex.
|
35
|
-
it { Color.new("000000").hex.
|
33
|
+
it { Color.new("#FFFFFF").hex.should eql "#FFFFFF" }
|
34
|
+
it { Color.new("#00F").hex.should eql "#0000FF" }
|
35
|
+
it { Color.new("000000").hex.should eql "#000000" }
|
36
36
|
end
|
37
37
|
|
38
38
|
context "of invalid HEX" do
|
@@ -45,10 +45,10 @@ describe Color do
|
|
45
45
|
|
46
46
|
context "with an array" do
|
47
47
|
context "of valid RGB value" do
|
48
|
-
it { Color.new([240, 248, 255]).rgb.
|
49
|
-
it { Color.new([240, 230, 140]).rgb.
|
50
|
-
it { Color.new([245, 255, 250]).rgb.
|
51
|
-
it { Color.new([216, 191, 216]).rgb.
|
48
|
+
it { Color.new([240, 248, 255]).rgb.should eql [240, 248, 255] }
|
49
|
+
it { Color.new([240, 230, 140]).rgb.should eql [240, 230, 140] }
|
50
|
+
it { Color.new([245, 255, 250]).rgb.should eql [245, 255, 250] }
|
51
|
+
it { Color.new([216, 191, 216]).rgb.should eql [216, 191, 216] }
|
52
52
|
end
|
53
53
|
|
54
54
|
context "of invalid RGB value" do
|
@@ -60,24 +60,31 @@ describe Color do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
context "with a RGB or HSB object" do
|
63
|
-
it { Color.new(RGB.new 240, 248, 255).name.
|
64
|
-
it { Color.new(HSB.new 208, 6, 100).name.
|
65
|
-
it { Color.new(HEX.new '#F0F8FF').name.
|
63
|
+
it { Color.new(RGB.new 240, 248, 255).name.should eql "Alice Blue" }
|
64
|
+
it { Color.new(HSB.new 208, 6, 100).name.should eql "Alice Blue" }
|
65
|
+
it { Color.new(HEX.new '#F0F8FF').name.should eql "Alice Blue" }
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
describe "#_name,#_hex,#_rgb,#_hsb" do
|
70
|
+
it { Color.new("Alice Blue")._name.should be_instance_of NAME }
|
71
|
+
it { Color.new("Alice Blue")._hex.should be_instance_of HEX }
|
72
|
+
it { Color.new("Alice Blue")._rgb.should be_instance_of RGB }
|
73
|
+
it { Color.new("Alice Blue")._hsb.should be_instance_of HSB }
|
74
|
+
end
|
75
|
+
|
69
76
|
describe "#hex" do
|
70
|
-
it { Color.new("Alice Blue").hex.
|
71
|
-
it { Color.new("Khaki").hex.
|
72
|
-
it { Color.new("Mint Cream").hex.
|
73
|
-
it { Color.new("Thistle").hex.
|
77
|
+
it { Color.new("Alice Blue").hex.should eql "#F0F8FF" }
|
78
|
+
it { Color.new("Khaki").hex.should eql "#F0E68C" }
|
79
|
+
it { Color.new("Mint Cream").hex.should eql "#F5FFFA" }
|
80
|
+
it { Color.new("Thistle").hex.should eql "#D8BFD8" }
|
74
81
|
end
|
75
82
|
|
76
83
|
describe "#hsb" do
|
77
|
-
it { Color.new("Alice Blue").hsb.
|
78
|
-
it { Color.new("Khaki").hsb.
|
79
|
-
it { Color.new("Mint Cream").hsb.
|
80
|
-
it { Color.new("Thistle").hsb.
|
84
|
+
it { Color.new("Alice Blue").hsb.should eql [208, 6, 100] }
|
85
|
+
it { Color.new("Khaki").hsb.should eql [55, 42, 94] }
|
86
|
+
it { Color.new("Mint Cream").hsb.should eql [150, 4, 100] }
|
87
|
+
it { Color.new("Thistle").hsb.should eql [300, 12, 85] }
|
81
88
|
end
|
82
89
|
|
83
90
|
describe '#red, #green, #blue, #hue, #sat, #bright' do
|
@@ -119,7 +126,7 @@ describe Color do
|
|
119
126
|
end
|
120
127
|
|
121
128
|
context "when color is not in X11 colorset" do
|
122
|
-
it { Color.new([100,10,10]).name.should
|
129
|
+
it { Color.new([100,10,10]).name.should be_empty }
|
123
130
|
end
|
124
131
|
end
|
125
132
|
|
@@ -152,7 +159,7 @@ describe Color do
|
|
152
159
|
end
|
153
160
|
|
154
161
|
context "when color is not in X11 colorset" do
|
155
|
-
it { Color.new([100,10,10]).name.should
|
162
|
+
it { Color.new([100,10,10]).name.should be_empty }
|
156
163
|
end
|
157
164
|
end
|
158
165
|
|
@@ -177,10 +184,6 @@ describe Color do
|
|
177
184
|
end
|
178
185
|
|
179
186
|
describe "#to_s" do
|
180
|
-
context "default" do
|
181
|
-
it { Color.new(:alice_blue).to_s.should eql "Alice Blue" }
|
182
|
-
end
|
183
|
-
|
184
187
|
context "with name mode" do
|
185
188
|
before do
|
186
189
|
@c = Color.new(:alice_blue)
|
@@ -209,6 +212,11 @@ describe Color do
|
|
209
212
|
end
|
210
213
|
end
|
211
214
|
|
215
|
+
describe "#inspect" do
|
216
|
+
subject { Color.new :alice_blue }
|
217
|
+
its(:inspect) { should eql "#<Colorable::Color 'Alice Blue<rgb(240,248,255)/hsb(208,6,100)/#F0F8FF>'>"}
|
218
|
+
end
|
219
|
+
|
212
220
|
describe "#+" do
|
213
221
|
context "with :NAME mode" do
|
214
222
|
before { @c = Color.new :khaki }
|
@@ -235,6 +243,24 @@ describe Color do
|
|
235
243
|
it { @c2.to_s.should eql "hsb(350,20,85)" }
|
236
244
|
it { @c.to_s.should eql "hsb(250,10,80)" }
|
237
245
|
end
|
246
|
+
|
247
|
+
context "pass a RGB object" do
|
248
|
+
before(:each) do
|
249
|
+
@a = Color.new('Red')
|
250
|
+
@b = Color.new('Green')
|
251
|
+
@c = Color.new('Blue')
|
252
|
+
@d = Color.new([255, 0, 0])
|
253
|
+
@e = Color.new([0, 255, 0])
|
254
|
+
@f = Color.new([0, 0, 255])
|
255
|
+
end
|
256
|
+
it { (@a + @b).to_s.should eql "Yellow" }
|
257
|
+
it { (@b + @c).to_s.should eql "Aqua" }
|
258
|
+
it { (@a + @c).to_s.should eql "Fuchsia" }
|
259
|
+
it { (@a + @b + @c).to_s.should eql "White" }
|
260
|
+
it { (@e + @a).to_s.should eql "rgb(255,255,0)" }
|
261
|
+
it { (@f + @b).to_s.should eql "rgb(0,255,255)" }
|
262
|
+
it { (@d + @e + @f).to_s.should eql "rgb(255,255,255)" }
|
263
|
+
end
|
238
264
|
end
|
239
265
|
|
240
266
|
describe "#-" do
|
@@ -263,6 +289,64 @@ describe Color do
|
|
263
289
|
it { @c.to_s.should eql "hsb(350,20,85)" }
|
264
290
|
it { @c2.to_s.should eql "hsb(250,10,80)" }
|
265
291
|
end
|
292
|
+
|
293
|
+
context "pass a RGB object" do
|
294
|
+
before(:each) do
|
295
|
+
@a = Color.new('Red')
|
296
|
+
@b = Color.new('Green')
|
297
|
+
@c = Color.new('Blue')
|
298
|
+
@d = Color.new([255, 0, 0])
|
299
|
+
@e = Color.new([0, 255, 0])
|
300
|
+
@f = Color.new([0, 0, 255])
|
301
|
+
end
|
302
|
+
it { (@a - @b).to_s.should eql "Black" }
|
303
|
+
it { (@b - @c).to_s.should eql "Black" }
|
304
|
+
it { (@a - @c).to_s.should eql "Black" }
|
305
|
+
it { (@a - @b - @c).to_s.should eql "Black" }
|
306
|
+
it { (@e - @a).to_s.should eql "rgb(0,0,0)" }
|
307
|
+
it { (@f - @b).to_s.should eql "rgb(0,0,0)" }
|
308
|
+
it { (@d - @e - @f).to_s.should eql "rgb(0,0,0)" }
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
describe "#*" do
|
313
|
+
context "pass a RGB object" do
|
314
|
+
before(:each) do
|
315
|
+
@a = Color.new('Red')
|
316
|
+
@b = Color.new('Green')
|
317
|
+
@c = Color.new('Blue')
|
318
|
+
@d = Color.new([255, 0, 0])
|
319
|
+
@e = Color.new([0, 255, 0])
|
320
|
+
@f = Color.new([0, 0, 255])
|
321
|
+
end
|
322
|
+
it { (@a * @b).to_s.should eql "Black" }
|
323
|
+
it { (@b * @c).to_s.should eql "Black" }
|
324
|
+
it { (@a * @c).to_s.should eql "Black" }
|
325
|
+
it { (@a * @b * @c).to_s.should eql "Black" }
|
326
|
+
it { (@e * @a).to_s.should eql "rgb(0,0,0)" }
|
327
|
+
it { (@f * @b).to_s.should eql "rgb(0,0,0)" }
|
328
|
+
it { (@d * @e * @f).to_s.should eql "rgb(0,0,0)" }
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
describe "#/" do
|
333
|
+
context "pass a RGB object" do
|
334
|
+
before(:each) do
|
335
|
+
@a = Color.new('Red')
|
336
|
+
@b = Color.new('Green')
|
337
|
+
@c = Color.new('Blue')
|
338
|
+
@d = Color.new([255, 0, 0])
|
339
|
+
@e = Color.new([0, 255, 0])
|
340
|
+
@f = Color.new([0, 0, 255])
|
341
|
+
end
|
342
|
+
it { (@a / @b).to_s.should eql "Yellow" }
|
343
|
+
it { (@b / @c).to_s.should eql "Aqua" }
|
344
|
+
it { (@a / @c).to_s.should eql "Fuchsia" }
|
345
|
+
it { (@a / @b / @c).to_s.should eql "White" }
|
346
|
+
it { (@e / @a).to_s.should eql "rgb(255,255,0)" }
|
347
|
+
it { (@f / @b).to_s.should eql "rgb(0,255,255)" }
|
348
|
+
it { (@d / @e / @f).to_s.should eql "rgb(255,255,255)" }
|
349
|
+
end
|
266
350
|
end
|
267
351
|
|
268
352
|
describe "#dark?" do
|
@@ -273,12 +357,12 @@ describe Color do
|
|
273
357
|
describe "#info" do
|
274
358
|
it 'returns data of the color' do
|
275
359
|
info = {
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
360
|
+
name:'Black',
|
361
|
+
rgb:[0, 0, 0],
|
362
|
+
hsb:[0, 0, 0],
|
363
|
+
hex:'#000000',
|
364
|
+
mode: :NAME,
|
365
|
+
dark:true
|
282
366
|
}
|
283
367
|
Color.new(:black).info.should eql info
|
284
368
|
end
|