colir 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +4 -0
- data/.travis.yml +14 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +2 -0
- data/LICENCE +19 -0
- data/README.md +186 -0
- data/Rakefile +15 -0
- data/VERSION +1 -0
- data/colir.gemspec +18 -0
- data/lib/colir.rb +357 -0
- data/lib/colir/hslrgb.rb +188 -0
- data/spec/colir_spec.rb +407 -0
- data/spec/helper.rb +10 -0
- data/spec/hslrgb/hsl_spec.rb +69 -0
- data/spec/hslrgb/rgb_spec.rb +80 -0
- data/spec/hslrgb_spec.rb +206 -0
- metadata +102 -0
data/spec/helper.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
describe Colir::HSLRGB::HSL do
|
4
|
+
|
5
|
+
describe "::valid_hsl?" do
|
6
|
+
describe "parameters" do
|
7
|
+
it "returns false if it's too long" do
|
8
|
+
Colir::HSLRGB::HSL.valid_hsl?([0, 0, 0, 0]).should.be.equal false
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns false if it's too short" do
|
12
|
+
Colir::HSLRGB::HSL.valid_hsl?([0, 0]).should.be.equal false
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "H" do
|
16
|
+
it "returns true if it's coverd by the range" do
|
17
|
+
Colir::HSLRGB::HSL.valid_hsl?([0, 0, 0]).should.be.equal true
|
18
|
+
Colir::HSLRGB::HSL.valid_hsl?([360, 0.9, 0.9]).should.be.equal true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns false if it's too low" do
|
22
|
+
Colir::HSLRGB::HSL.valid_hsl?([-1, 0, 0]).should.be.equal false
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns false if it's too high" do
|
26
|
+
Colir::HSLRGB::HSL.valid_hsl?([361, 1, 1]).should.be.equal false
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns false if it's not integer" do
|
30
|
+
Colir::HSLRGB::HSL.valid_hsl?([359.1, 0, 0]).should.be.equal false
|
31
|
+
Colir::HSLRGB::HSL.valid_hsl?(
|
32
|
+
[Rational(3591, 10), 0, 0]
|
33
|
+
).should.be.equal false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "S" do
|
38
|
+
it "returns true if it's coverd by the range" do
|
39
|
+
Colir::HSLRGB::HSL.valid_hsl?([0, 0, 0]).should.be.equal true
|
40
|
+
Colir::HSLRGB::HSL.valid_hsl?([360, 0.9, 0.9]).should.be.equal true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns false if it's too low" do
|
44
|
+
Colir::HSLRGB::HSL.valid_hsl?([0, -0.1, 0]).should.be.equal false
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns false if it's too high" do
|
48
|
+
Colir::HSLRGB::HSL.valid_hsl?([360, 1.1, 1]).should.be.equal false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "L" do
|
53
|
+
it "returns true if it's coverd by the range" do
|
54
|
+
Colir::HSLRGB::HSL.valid_hsl?([0, 0, 0]).should.be.equal true
|
55
|
+
Colir::HSLRGB::HSL.valid_hsl?([360, 0.9, 0.9]).should.be.equal true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns false if it's too low" do
|
59
|
+
Colir::HSLRGB::HSL.valid_hsl?([0, 0, -0.1]).should.be.equal false
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns false if it's too high" do
|
63
|
+
Colir::HSLRGB::HSL.valid_hsl?([360, 1, 1.1]).should.be.equal false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
|
3
|
+
describe Colir::HSLRGB::RGB do
|
4
|
+
|
5
|
+
describe "::valid_rgb?" do
|
6
|
+
describe "parameters" do
|
7
|
+
it "returns false if it's too long" do
|
8
|
+
Colir::HSLRGB::RGB.valid_rgb?([255, 255, 255, 255]).should.be.equal false
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns false if it's too short" do
|
12
|
+
Colir::HSLRGB::RGB.valid_rgb?([255, 255]).should.be.equal false
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "R" do
|
16
|
+
it "returns true if it's coverd by the range" do
|
17
|
+
Colir::HSLRGB::RGB.valid_rgb?([255, 255, 255]).should.be.equal true
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns false if it's too low" do
|
21
|
+
Colir::HSLRGB::RGB.valid_rgb?([-1, 0, 0]).should.be.equal false
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns false if it's too high" do
|
25
|
+
Colir::HSLRGB::RGB.valid_rgb?([256, 255, 255]).should.be.equal false
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns false if it's not integer" do
|
29
|
+
Colir::HSLRGB::RGB.valid_rgb?([254.1, 255, 255]).should.be.equal false
|
30
|
+
Colir::HSLRGB::RGB.valid_rgb?(
|
31
|
+
[Rational(2541, 10), 255, 255]
|
32
|
+
).should.be.equal false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "G" do
|
37
|
+
it "returns true if it's coverd by the range" do
|
38
|
+
Colir::HSLRGB::RGB.valid_rgb?([255, 255, 255]).should.be.equal true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns false if it's too low" do
|
42
|
+
Colir::HSLRGB::RGB.valid_rgb?([0, -1, 0]).should.be.equal false
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns false if it's too high" do
|
46
|
+
Colir::HSLRGB::RGB.valid_rgb?([255, 256, 255]).should.be.equal false
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns false if it's not integer" do
|
50
|
+
Colir::HSLRGB::RGB.valid_rgb?([255, 254.1, 255]).should.be.equal false
|
51
|
+
Colir::HSLRGB::RGB.valid_rgb?(
|
52
|
+
[255, Rational(2541, 10), 255]
|
53
|
+
).should.be.equal false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "B" do
|
58
|
+
it "returns true if it's coverd by the range" do
|
59
|
+
Colir::HSLRGB::RGB.valid_rgb?([255, 255, 255]).should.be.equal true
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns false if it's too low" do
|
63
|
+
Colir::HSLRGB::RGB.valid_rgb?([0, 0, -1]).should.be.equal false
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns false if it's too high" do
|
67
|
+
Colir::HSLRGB::RGB.valid_rgb?([255, 255, 256]).should.be.equal false
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns false if it's not integer" do
|
71
|
+
Colir::HSLRGB::RGB.valid_rgb?([255, 255, 254.1]).should.be.equal false
|
72
|
+
Colir::HSLRGB::RGB.valid_rgb?(
|
73
|
+
[255, 255, Rational(2541, 10)]
|
74
|
+
).should.be.equal false
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
data/spec/hslrgb_spec.rb
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
describe Colir::HSLRGB do
|
4
|
+
|
5
|
+
describe "::rgb_to_hsl" do
|
6
|
+
it "converts black RGB colour to its HSL equivalent" do
|
7
|
+
Colir::HSLRGB.rgb_to_hsl(0x00, 0x00, 0x00).should == [0, 0, 0]
|
8
|
+
end
|
9
|
+
|
10
|
+
it "converts white RGB colour to its HSL equivalent" do
|
11
|
+
Colir::HSLRGB.rgb_to_hsl(0xff, 0xff, 0xff).should == [0, 0, 1]
|
12
|
+
end
|
13
|
+
|
14
|
+
it "converts reddish RGB colour to its HSL equivalent" do
|
15
|
+
Colir::HSLRGB.rgb_to_hsl(0x99, 0x00, 0x00).should == [0, 1.0, 0.3]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "converts orangish RGB colour to its HSL equivalent" do
|
19
|
+
hsl = Colir::HSLRGB.rgb_to_hsl(0xff, 0xa3, 0x19)
|
20
|
+
hsl[0].should == 36
|
21
|
+
hsl[1].should == 1.0
|
22
|
+
hsl[2].round(2).should == 0.55
|
23
|
+
end
|
24
|
+
|
25
|
+
it "converts yellowish RGB colour to its HSL equivalent" do
|
26
|
+
hsl = Colir::HSLRGB.rgb_to_hsl(0xff, 0xff, 0x19)
|
27
|
+
hsl[0].should == 60
|
28
|
+
hsl[1].should == 1.0
|
29
|
+
hsl[2].round(2).should == 0.55
|
30
|
+
end
|
31
|
+
|
32
|
+
it "converts greenish RGB colour to its HSL equivalent" do
|
33
|
+
Colir::HSLRGB.rgb_to_hsl(0x33, 0xcc, 0x33).should == [120, 0.6, 0.5]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "converts bluish RGB colour to its HSL equivalent" do
|
37
|
+
hsl = Colir::HSLRGB.rgb_to_hsl(0x19, 0xff, 0xff)
|
38
|
+
hsl[0].should == 180
|
39
|
+
hsl[1].should == 1.0
|
40
|
+
hsl[2].round(2) == 0.55
|
41
|
+
end
|
42
|
+
|
43
|
+
it "converts indigish RGB colour to its HSL equivalent" do
|
44
|
+
Colir::HSLRGB.rgb_to_hsl(0x00, 0x66, 0xff).should == [216, 1.0, 0.5]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "converts violetish RGB colour to its HSL equivalent" do
|
48
|
+
Colir::HSLRGB.rgb_to_hsl(0x99, 0x33, 0xff).should == [270, 1.0, 0.6]
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "return value" do
|
52
|
+
before do
|
53
|
+
@hsl = Colir::HSLRGB.rgb_to_hsl(0xaf, 0xfe, 0x39)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should be Array" do
|
57
|
+
@hsl.should.be kind_of(Array)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns an integer hue" do
|
61
|
+
@hsl[0].should.be kind_of(Integer)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns a BigDecimal saturation" do
|
65
|
+
@hsl[1].should.be kind_of(BigDecimal)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "returns a BigDecimal lightness" do
|
69
|
+
@hsl[2].should.be kind_of(BigDecimal)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "parameters" do
|
74
|
+
describe "R" do
|
75
|
+
it "raises RangeError if it's too low" do
|
76
|
+
should.raise(RangeError) {
|
77
|
+
Colir::HSLRGB.rgb_to_hsl(-1, 0, 0)
|
78
|
+
}.message =~ /out of allowed RGB values \(0-255\)/
|
79
|
+
end
|
80
|
+
|
81
|
+
it "raises RangeError if it's too high" do
|
82
|
+
should.raise(RangeError) {
|
83
|
+
Colir::HSLRGB.rgb_to_hsl(256, 255, 255)
|
84
|
+
}.message =~ /out of allowed RGB values \(0-255\)/
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "G" do
|
89
|
+
it "raises RangeError if it's too low" do
|
90
|
+
should.raise(RangeError) {
|
91
|
+
Colir::HSLRGB.rgb_to_hsl(0, -1, 0)
|
92
|
+
}.message =~ /out of allowed RGB values \(0-255\)/
|
93
|
+
end
|
94
|
+
|
95
|
+
it "raises RangeError if it's too high" do
|
96
|
+
should.raise(RangeError) {
|
97
|
+
Colir::HSLRGB.rgb_to_hsl(255, 256, 255)
|
98
|
+
}.message =~ /out of allowed RGB values \(0-255\)/
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "B" do
|
104
|
+
it "raises RangeError if it's too low" do
|
105
|
+
should.raise(RangeError) {
|
106
|
+
Colir::HSLRGB.rgb_to_hsl(0, 0, -1)
|
107
|
+
}.message =~ /out of allowed RGB values \(0-255\)/
|
108
|
+
end
|
109
|
+
|
110
|
+
it "raises RangeError if it's too high" do
|
111
|
+
should.raise(RangeError) {
|
112
|
+
Colir::HSLRGB.rgb_to_hsl(255, 255, 256)
|
113
|
+
}.message =~ /out of allowed RGB values \(0-255\)/
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "::hsl_to_rgb" do
|
120
|
+
it "converts black HSL colour to its RGB equivalent" do
|
121
|
+
Colir::HSLRGB.hsl_to_rgb(0, 0, 0).should == [0, 0, 0]
|
122
|
+
end
|
123
|
+
|
124
|
+
it "converts white HSL colour to its RGB equivalent" do
|
125
|
+
Colir::HSLRGB.hsl_to_rgb(0, 0, 1.0).should == [0xff, 0xff, 0xff]
|
126
|
+
end
|
127
|
+
|
128
|
+
it "converts greyish HSL colour to its RGB equivalent" do
|
129
|
+
Colir::HSLRGB.hsl_to_rgb(360, 0, 0.8).should == [0xcc, 0xcc, 0xcc]
|
130
|
+
end
|
131
|
+
|
132
|
+
it "converts reddish HSL colour to its RGB equivalent" do
|
133
|
+
Colir::HSLRGB.hsl_to_rgb(0, 1.0, 0.3).should == [0x99, 0x00, 0x00]
|
134
|
+
end
|
135
|
+
|
136
|
+
it "converts orangish HSL colour to its RGB equivalent" do
|
137
|
+
Colir::HSLRGB.hsl_to_rgb(36, 1.0, 0.55).should == [0xff, 0xa3, 0x1a]
|
138
|
+
end
|
139
|
+
|
140
|
+
it "converts yellowish HSL colour to its RGB equivalent" do
|
141
|
+
Colir::HSLRGB.hsl_to_rgb(60, 1.0, 0.55).should == [0xff, 0xff, 0x1a]
|
142
|
+
end
|
143
|
+
|
144
|
+
it "converts greenish HSL colour to its RGB equivalent" do
|
145
|
+
Colir::HSLRGB.hsl_to_rgb(120, 0.6, 0.5).should == [0x33, 0xcc, 0x33]
|
146
|
+
end
|
147
|
+
|
148
|
+
it "converts bluish HSL colour to its RGB equivalent" do
|
149
|
+
Colir::HSLRGB.hsl_to_rgb(180, 1.0, 0.55).should == [0x1a, 0xff, 0xff]
|
150
|
+
end
|
151
|
+
|
152
|
+
it "converts indigish HSL colour to its RGB equivalent" do
|
153
|
+
Colir::HSLRGB.hsl_to_rgb(216, 1.0, 0.5).should == [0x00, 0x66, 0xff]
|
154
|
+
end
|
155
|
+
|
156
|
+
it "converts violetish HSL colour to its RGB equivalent" do
|
157
|
+
Colir::HSLRGB.hsl_to_rgb(270, 1.0, 0.6).should == [0x99, 0x33, 0xff]
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "parameters" do
|
161
|
+
describe "H" do
|
162
|
+
it "raises RangeError if it's too low" do
|
163
|
+
should.raise(RangeError) {
|
164
|
+
Colir::HSLRGB.hsl_to_rgb(-1, 0, 0)
|
165
|
+
}.message =~ /out of allowed HSL values/
|
166
|
+
end
|
167
|
+
|
168
|
+
it "raises RangeError if it's too high" do
|
169
|
+
should.raise(RangeError) {
|
170
|
+
Colir::HSLRGB.hsl_to_rgb(361, 1, 1)
|
171
|
+
}.message =~ /out of allowed HSL values/
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "S" do
|
176
|
+
it "raises RangeError if it's too low" do
|
177
|
+
should.raise(RangeError) {
|
178
|
+
Colir::HSLRGB.hsl_to_rgb(0, -0.1, 0)
|
179
|
+
}.message =~ /out of allowed HSL values/
|
180
|
+
end
|
181
|
+
|
182
|
+
it "raises RangeError if it's too high" do
|
183
|
+
should.raise(RangeError) {
|
184
|
+
Colir::HSLRGB.hsl_to_rgb(360, 1.1, 1)
|
185
|
+
}.message =~ /out of allowed HSL values/
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "L" do
|
191
|
+
it "raises RangeError if it's too low" do
|
192
|
+
should.raise(RangeError) {
|
193
|
+
Colir::HSLRGB.hsl_to_rgb(0, 1, -0.1)
|
194
|
+
}.message =~ /out of allowed HSL values/
|
195
|
+
end
|
196
|
+
|
197
|
+
it "raises RangeError if it's too high" do
|
198
|
+
should.raise(RangeError) {
|
199
|
+
Colir::HSLRGB.hsl_to_rgb(360, 1, 1.1)
|
200
|
+
}.message =~ /out of allowed HSL values/
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: colir
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyrylo Silin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bacon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: This library is about HEX colours.
|
56
|
+
email: kyrylosilin@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- .gitignore
|
62
|
+
- .travis.yml
|
63
|
+
- CHANGELOG.md
|
64
|
+
- Gemfile
|
65
|
+
- LICENCE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- VERSION
|
69
|
+
- colir.gemspec
|
70
|
+
- lib/colir.rb
|
71
|
+
- lib/colir/hslrgb.rb
|
72
|
+
- spec/colir_spec.rb
|
73
|
+
- spec/helper.rb
|
74
|
+
- spec/hslrgb/hsl_spec.rb
|
75
|
+
- spec/hslrgb/rgb_spec.rb
|
76
|
+
- spec/hslrgb_spec.rb
|
77
|
+
homepage: https://github.com/kyrylo/colir
|
78
|
+
licenses:
|
79
|
+
- zlib
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.0.3
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Colir means colour in Ukrainan. In Ruby it means HEX colour
|
101
|
+
test_files: []
|
102
|
+
has_rdoc:
|