paleta 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paleta/color.rb +9 -1
- data/lib/paleta/version.rb +1 -1
- data/spec/models/color_spec.rb +59 -38
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2a306c36ae6e1a659170b8a0e45ef52cc0df8d4
|
4
|
+
data.tar.gz: eeaec953fa8e5a7d6b4d6205d153d464d1ea0e32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c8a0bfc98c27f9712446e4f0956ea04ee4efe29b364beb699152a6731479264ea0d2bedd52e0bbd7961a8e3f02f1e8f73dd6d69fb936d81bdbb2c721e03b72e
|
7
|
+
data.tar.gz: 0c30bb441600cc863bcee8f5d7190b502f3741d49f93d4e46e17999f8ff981224bbefe8dff850d43cd390b0355e82b16af52f6fe53e7b0ec5311c4de57bff26c
|
data/lib/paleta/color.rb
CHANGED
@@ -42,7 +42,15 @@ module Paleta
|
|
42
42
|
end
|
43
43
|
elsif args.length == 2 && args[0] == :hex && args[1].is_a?(String)
|
44
44
|
# example: new(:hex, "336699")
|
45
|
-
|
45
|
+
# example: new(:hex, "#336699")
|
46
|
+
# example: new(:hex, "#fff")
|
47
|
+
color_hex = args[1]
|
48
|
+
color_hex = color_hex[1..-1] if color_hex.start_with?('#')
|
49
|
+
|
50
|
+
# These are all string operations to make a "fea" into a "ffeeaa"
|
51
|
+
color_hex = color_hex[0] * 2 + color_hex[1] * 2 + color_hex[2] * 2 if color_hex.length == 3
|
52
|
+
|
53
|
+
hex_init(color_hex)
|
46
54
|
elsif args.length == 3 && args[0].is_a?(Numeric) && args[1].is_a?(Numeric) && args[2].is_a?(Numeric)
|
47
55
|
# example: new(235, 129, 74)
|
48
56
|
rgb_init(args[0], args[1], args[2])
|
data/lib/paleta/version.rb
CHANGED
data/spec/models/color_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paleta::Color do
|
4
4
|
it "should initialize with RGB components in 0..255" do
|
@@ -7,14 +7,35 @@ describe Paleta::Color do
|
|
7
7
|
color.green.should == 161
|
8
8
|
color.blue.should == 235
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
it "should initialize with the :hex flag and a valid 6 character HEX string" do
|
12
12
|
color = Paleta::Color.new(:hex, "5EA1EB")
|
13
13
|
color.red.should == 94
|
14
14
|
color.green.should == 161
|
15
15
|
color.blue.should == 235
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
|
+
it "should initialize with the :hex flag and a valid 7 character HEX string" do
|
19
|
+
color = Paleta::Color.new(:hex, "#5EA1EB")
|
20
|
+
color.red.should == 94
|
21
|
+
color.green.should == 161
|
22
|
+
color.blue.should == 235
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should initialize with the :hex flag and a valid 3 character HEX string" do
|
26
|
+
color = Paleta::Color.new(:hex, "5EA")
|
27
|
+
color.red.should == 85
|
28
|
+
color.green.should == 238
|
29
|
+
color.blue.should == 170
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should initialize with the :hex flag and a valid 4 character HEX string" do
|
33
|
+
color = Paleta::Color.new(:hex, "#5EA")
|
34
|
+
color.red.should == 85
|
35
|
+
color.green.should == 238
|
36
|
+
color.blue.should == 170
|
37
|
+
end
|
38
|
+
|
18
39
|
it "should initialize with the :hsl flag, hue in 0..360, and saturation and lightness in 0..100" do
|
19
40
|
color = Paleta::Color.new(:hsl, 0, 0, 100)
|
20
41
|
color.hue.should == 0
|
@@ -25,38 +46,38 @@ describe Paleta::Color do
|
|
25
46
|
color.blue.should == 255
|
26
47
|
color.hex.should == "FFFFFF"
|
27
48
|
end
|
28
|
-
|
49
|
+
|
29
50
|
it "should initialize with the :rgb flag with RGB components in 0..255" do
|
30
51
|
color = Paleta::Color.new(:rgb, 94, 161, 235)
|
31
52
|
color.red.should == 94
|
32
53
|
color.green.should == 161
|
33
54
|
color.blue.should == 235
|
34
55
|
end
|
35
|
-
|
56
|
+
|
36
57
|
it "should raise an error on an invalid format flag" do
|
37
58
|
expect{ Paleta::Color.new(:something, 50, 50, 50) }.to raise_error(ArgumentError)
|
38
59
|
end
|
39
|
-
|
60
|
+
|
40
61
|
it "should raise an error on an invalid hex string" do
|
41
62
|
expect{ Paleta::Color.new(:hex, "xkfjs") }.to raise_error(ArgumentError)
|
42
63
|
end
|
43
|
-
|
64
|
+
|
44
65
|
it "should raise an error on RGB components not in 0..255" do
|
45
66
|
expect{ Paleta::Color.new(-74, 333, 4321) }.to raise_error(ArgumentError)
|
46
67
|
end
|
47
|
-
|
68
|
+
|
48
69
|
it "should raise an error on hue not in 0..360" do
|
49
70
|
expect{ Paleta::Color.new(:hsl, 400, 50, 50) }.to raise_error(ArgumentError)
|
50
71
|
end
|
51
|
-
|
72
|
+
|
52
73
|
it "should raise an error on saturation not in 0..100" do
|
53
74
|
expect{ Paleta::Color.new(:hsl, 200, 150, 50) }.to raise_error(ArgumentError)
|
54
75
|
end
|
55
|
-
|
76
|
+
|
56
77
|
it "should raise an error on lightness not in 0..100" do
|
57
78
|
expect{ Paleta::Color.new(:hsl, 200, 50, 150) }.to raise_error(ArgumentError)
|
58
79
|
end
|
59
|
-
|
80
|
+
|
60
81
|
it "should determine its equality to another Color" do
|
61
82
|
color1 = Paleta::Color.new(237, 172, 33)
|
62
83
|
color2 = Paleta::Color.new(:hex, "EDAC21")
|
@@ -66,51 +87,51 @@ describe Paleta::Color do
|
|
66
87
|
obj = Object.new
|
67
88
|
(color1 == obj).should be_false
|
68
89
|
end
|
69
|
-
|
90
|
+
|
70
91
|
it "should calculate its HSL value on itialization" do
|
71
92
|
color = Paleta::Color.new(237, 172, 33)
|
72
93
|
color.hue.to_i.should == 40
|
73
94
|
color.saturation.to_i.should == 85
|
74
95
|
color.lightness.to_i.should == 52
|
75
96
|
end
|
76
|
-
|
97
|
+
|
77
98
|
it "should update its HSL value when its RGB value is updated" do
|
78
99
|
color = Paleta::Color.new(237, 172, 33)
|
79
|
-
|
100
|
+
|
80
101
|
color.red = 0
|
81
102
|
color.hue.to_i.should == 131
|
82
103
|
color.saturation.to_i.should == 100
|
83
104
|
color.lightness.to_i.should == 33
|
84
|
-
|
105
|
+
|
85
106
|
color.green = 123
|
86
107
|
color.hue.to_i.should == 136
|
87
|
-
color.saturation.to_i.should ==
|
108
|
+
color.saturation.to_i.should == 100
|
88
109
|
color.lightness.to_i.should == 24
|
89
|
-
|
110
|
+
|
90
111
|
color.blue = 241
|
91
112
|
color.hue.to_i.should == 209
|
92
113
|
color.saturation.to_i.should == 100
|
93
114
|
color.lightness.to_i.should == 47
|
94
115
|
end
|
95
|
-
|
116
|
+
|
96
117
|
it "should update its RGB value when its HSL value is updated" do
|
97
118
|
color = Paleta::Color.new(0, 0, 255)
|
98
119
|
color.hue = 120
|
99
120
|
color.red.to_i.should == 0
|
100
121
|
color.green.to_i.should == 255
|
101
122
|
color.blue.to_i.should == 0
|
102
|
-
|
123
|
+
|
103
124
|
color.saturation = 50
|
104
125
|
color.red.to_i.should == 63
|
105
126
|
color.green.to_i.should == 191
|
106
127
|
color.blue.to_i.should == 63
|
107
|
-
|
128
|
+
|
108
129
|
color.lightness = 80
|
109
130
|
color.red.to_i.should == 178
|
110
131
|
color.green.to_i.should == 229
|
111
132
|
color.blue.to_i.should == 178
|
112
133
|
end
|
113
|
-
|
134
|
+
|
114
135
|
it "should lighten itself by a percentage" do
|
115
136
|
color = Paleta::Color.new(94, 161, 235)
|
116
137
|
lightness = color.lightness
|
@@ -120,7 +141,7 @@ describe Paleta::Color do
|
|
120
141
|
color.lighten!(20)
|
121
142
|
color.lightness.should == lightness + 20
|
122
143
|
end
|
123
|
-
|
144
|
+
|
124
145
|
it "should return a copy of itself, lightened by a percentage" do
|
125
146
|
color = Paleta::Color.new(94, 161, 235)
|
126
147
|
lightness = color.lightness
|
@@ -128,13 +149,13 @@ describe Paleta::Color do
|
|
128
149
|
copy.lightness.should == lightness + 20
|
129
150
|
color.lightness.should == lightness
|
130
151
|
end
|
131
|
-
|
152
|
+
|
132
153
|
it "should quietly maintain a maximum of 100 when lightening" do
|
133
154
|
color = Paleta::Color.new(94, 161, 235)
|
134
155
|
color.lighten!(300)
|
135
156
|
color.lightness.should == 100
|
136
157
|
end
|
137
|
-
|
158
|
+
|
138
159
|
it "should darken by a percentage" do
|
139
160
|
color = Paleta::Color.new(94, 161, 235)
|
140
161
|
lightness = color.lightness
|
@@ -144,7 +165,7 @@ describe Paleta::Color do
|
|
144
165
|
color.darken!(20)
|
145
166
|
color.lightness.should == lightness - 20
|
146
167
|
end
|
147
|
-
|
168
|
+
|
148
169
|
it "should return a copy of itself, darkened by a percentage" do
|
149
170
|
color = Paleta::Color.new(94, 161, 235)
|
150
171
|
lightness = color.lightness
|
@@ -152,13 +173,13 @@ describe Paleta::Color do
|
|
152
173
|
copy.lightness.should == lightness - 20
|
153
174
|
color.lightness.should == lightness
|
154
175
|
end
|
155
|
-
|
176
|
+
|
156
177
|
it "should quietly maintain a minimum of 0 when darkening" do
|
157
178
|
color = Paleta::Color.new(94, 161, 235)
|
158
179
|
color.darken!(300)
|
159
180
|
color.lightness.should == 0
|
160
181
|
end
|
161
|
-
|
182
|
+
|
162
183
|
it "should invert" do
|
163
184
|
color = Paleta::Color.new(94, 161, 235)
|
164
185
|
color.invert!
|
@@ -166,7 +187,7 @@ describe Paleta::Color do
|
|
166
187
|
color.green.should == 94
|
167
188
|
color.blue.should == 20
|
168
189
|
end
|
169
|
-
|
190
|
+
|
170
191
|
it "should return an inverted copy of itself" do
|
171
192
|
color = Paleta::Color.new(94, 161, 235)
|
172
193
|
copy = color.invert
|
@@ -177,7 +198,7 @@ describe Paleta::Color do
|
|
177
198
|
color.green.should == 161
|
178
199
|
color.blue.should == 235
|
179
200
|
end
|
180
|
-
|
201
|
+
|
181
202
|
it "should desaturate" do
|
182
203
|
color = Paleta::Color.new(94, 161, 235)
|
183
204
|
color.desaturate!
|
@@ -186,7 +207,7 @@ describe Paleta::Color do
|
|
186
207
|
color.green.to_i.should == 164
|
187
208
|
color.blue.to_i.should == 164
|
188
209
|
end
|
189
|
-
|
210
|
+
|
190
211
|
it "should return a desaturated copy of itself" do
|
191
212
|
color = Paleta::Color.new(94, 161, 235)
|
192
213
|
copy = color.desaturate
|
@@ -199,38 +220,38 @@ describe Paleta::Color do
|
|
199
220
|
color.green.should == 161
|
200
221
|
color.blue.should == 235
|
201
222
|
end
|
202
|
-
|
223
|
+
|
203
224
|
it "should become its complement" do
|
204
225
|
color = Paleta::Color.new(:hsl, 90, 50, 50)
|
205
226
|
color.complement!
|
206
227
|
color.hue.to_i.should == 270
|
207
228
|
end
|
208
|
-
|
229
|
+
|
209
230
|
it "should return its complement Color" do
|
210
231
|
color = Paleta::Color.new(:hsl, 90, 50, 50)
|
211
232
|
complement = color.complement
|
212
233
|
complement.hue.to_i.should == 270
|
213
234
|
end
|
214
|
-
|
235
|
+
|
215
236
|
it "should calculate its similarity to another Color" do
|
216
237
|
color1 = Paleta::Color.new(94, 161, 235)
|
217
238
|
color2 = Paleta::Color.new(237, 172, 33)
|
218
239
|
color1.similarity(color2).round(5).should == 0.56091
|
219
|
-
|
240
|
+
|
220
241
|
color1 = Paleta::Color.new(237, 172, 33)
|
221
242
|
color2 = Paleta::Color.new(237, 172, 33)
|
222
243
|
color1.similarity(color2).should == 0
|
223
|
-
|
244
|
+
|
224
245
|
color1 = Paleta::Color.new(0, 0, 0)
|
225
246
|
color2 = Paleta::Color.new(255, 255, 255)
|
226
247
|
color1.similarity(color2).should == 1
|
227
248
|
end
|
228
|
-
|
249
|
+
|
229
250
|
it "should maintain its HEX value" do
|
230
251
|
color = Paleta::Color.new(94, 161, 235)
|
231
252
|
color.hex.should == "5EA1EB"
|
232
253
|
end
|
233
|
-
|
254
|
+
|
234
255
|
it "should update its HSB and RGB components when its HEX value is updated" do
|
235
256
|
color = Paleta::Color.new(100, 100, 100)
|
236
257
|
color.hex = "ffffff"
|
@@ -241,7 +262,7 @@ describe Paleta::Color do
|
|
241
262
|
color.saturation.should == 0
|
242
263
|
color.lightness.should == 100
|
243
264
|
end
|
244
|
-
|
265
|
+
|
245
266
|
it "should return an array of component values" do
|
246
267
|
c = Paleta::Color.new(30, 90, 120)
|
247
268
|
rgb_array = [c.red, c.green, c.blue]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paleta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Stephens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.4.5
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: A little library for creating, manipulating and comparing colors and color
|