color 1.4.2 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- checksums.yaml.gz.sig +2 -0
- data.tar.gz.sig +2 -3
- data/History.rdoc +33 -0
- data/Manifest.txt +1 -1
- data/README.rdoc +14 -2
- data/Rakefile +20 -5
- data/lib/color.rb +104 -53
- data/lib/color/cmyk.rb +39 -43
- data/lib/color/css.rb +1 -10
- data/lib/color/grayscale.rb +33 -34
- data/lib/color/hsl.rb +96 -65
- data/lib/color/palette/monocontrast.rb +24 -28
- data/lib/color/rgb.rb +152 -67
- data/lib/color/rgb/colors.rb +166 -0
- data/lib/color/rgb/metallic.rb +26 -29
- data/lib/color/yiq.rb +13 -23
- data/test/test_adobecolor.rb +2 -2
- data/test/test_cmyk.rb +2 -2
- data/test/test_color.rb +2 -3
- data/test/test_css.rb +11 -9
- data/test/test_gimp.rb +2 -2
- data/test/test_grayscale.rb +2 -2
- data/test/test_hsl.rb +2 -2
- data/test/test_monocontrast.rb +2 -2
- data/test/test_rgb.rb +38 -4
- data/test/test_yiq.rb +2 -2
- metadata +57 -94
- metadata.gz.sig +0 -0
- data/lib/color/rgb-colors.rb +0 -343
@@ -0,0 +1,166 @@
|
|
1
|
+
class Color::RGB
|
2
|
+
class << self
|
3
|
+
private
|
4
|
+
def named(rgb, *names)
|
5
|
+
__named_color(self, new(*rgb), *names)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
named [0xf0, 0xf8, 0xff], :AliceBlue
|
10
|
+
named [0xfa, 0xeb, 0xd7], :AntiqueWhite
|
11
|
+
named [0x00, 0xff, 0xff], :Aqua
|
12
|
+
named [0x7f, 0xff, 0xd4], :Aquamarine
|
13
|
+
named [0xf0, 0xff, 0xff], :Azure
|
14
|
+
named [0xf5, 0xf5, 0xdc], :Beige
|
15
|
+
named [0xff, 0xe4, 0xc4], :Bisque
|
16
|
+
named [0x00, 0x00, 0x00], :Black
|
17
|
+
named [0xff, 0xeb, 0xcd], :BlanchedAlmond
|
18
|
+
named [0x00, 0x00, 0xff], :Blue
|
19
|
+
named [0x8a, 0x2b, 0xe2], :BlueViolet
|
20
|
+
named [0xa5, 0x2a, 0x2a], :Brown
|
21
|
+
named [0xde, 0xb8, 0x87], :BurlyWood, :Burlywood
|
22
|
+
named [0x5f, 0x9e, 0xa0], :CadetBlue
|
23
|
+
named [0xff, 0x5e, 0xd0], :Carnation
|
24
|
+
named [0x8d, 0x00, 0x00], :Cayenne
|
25
|
+
named [0x7f, 0xff, 0x00], :Chartreuse
|
26
|
+
named [0xd2, 0x69, 0x1e], :Chocolate
|
27
|
+
named [0xff, 0x7f, 0x50], :Coral
|
28
|
+
named [0x64, 0x95, 0xed], :CornflowerBlue
|
29
|
+
named [0xff, 0xf8, 0xdc], :Cornsilk
|
30
|
+
named [0xdc, 0x14, 0x3c], :Crimson
|
31
|
+
named [0x00, 0xff, 0xff], :Cyan
|
32
|
+
named [0x00, 0x00, 0x8b], :DarkBlue
|
33
|
+
named [0x00, 0x8b, 0x8b], :DarkCyan
|
34
|
+
named [0xb8, 0x86, 0x0b], :DarkGoldenRod, :DarkGoldenrod
|
35
|
+
named [0xa9, 0xa9, 0xa9], :DarkGray, :DarkGrey
|
36
|
+
named [0x00, 0x64, 0x00], :DarkGreen
|
37
|
+
named [0xbd, 0xb7, 0x6b], :DarkKhaki
|
38
|
+
named [0x8b, 0x00, 0x8b], :DarkMagenta
|
39
|
+
named [0x55, 0x6b, 0x2f], :DarkOliveGreen, :DarkoliveGreen
|
40
|
+
named [0xff, 0x8c, 0x00], :DarkOrange
|
41
|
+
named [0x99, 0x32, 0xcc], :DarkOrchid
|
42
|
+
named [0x8b, 0x00, 0x00], :DarkRed
|
43
|
+
named [0xe9, 0x96, 0x7a], :DarkSalmon, :Darksalmon
|
44
|
+
named [0x8f, 0xbc, 0x8f], :DarkSeaGreen
|
45
|
+
named [0x48, 0x3d, 0x8b], :DarkSlateBlue
|
46
|
+
named [0x2f, 0x4f, 0x4f], :DarkSlateGray, :DarkSlateGrey
|
47
|
+
named [0x00, 0xce, 0xd1], :DarkTurquoise
|
48
|
+
named [0x94, 0x00, 0xd3], :DarkViolet
|
49
|
+
named [0xff, 0x8c, 0x00], :Darkorange
|
50
|
+
named [0xff, 0x14, 0x93], :DeepPink
|
51
|
+
named [0x00, 0xbf, 0xbf], :DeepSkyBlue
|
52
|
+
named [0x69, 0x69, 0x69], :DimGray, :DimGrey
|
53
|
+
named [0x1e, 0x90, 0xff], :DodgerBlue
|
54
|
+
named [0xd1, 0x92, 0x75], :Feldspar
|
55
|
+
named [0xb2, 0x22, 0x22], :FireBrick, :Firebrick
|
56
|
+
named [0xff, 0xfa, 0xf0], :FloralWhite
|
57
|
+
named [0x22, 0x8b, 0x22], :ForestGreen
|
58
|
+
named [0xff, 0x00, 0xff], :Fuchsia
|
59
|
+
named [0xdc, 0xdc, 0xdc], :Gainsboro
|
60
|
+
named [0xf8, 0xf8, 0xff], :GhostWhite
|
61
|
+
named [0xff, 0xd7, 0x00], :Gold
|
62
|
+
named [0xda, 0xa5, 0x20], :GoldenRod, :Goldenrod
|
63
|
+
named [0x80, 0x80, 0x80], :Gray, :Grey
|
64
|
+
named [10, 10, 10, 100.0], :Gray10, :Grey10
|
65
|
+
named [20, 20, 20, 100.0], :Gray20, :Grey20
|
66
|
+
named [30, 30, 30, 100.0], :Gray30, :Grey30
|
67
|
+
named [40, 40, 40, 100.0], :Gray40, :Grey40
|
68
|
+
named [50, 50, 50, 100.0], :Gray50, :Grey50
|
69
|
+
named [60, 60, 60, 100.0], :Gray60, :Grey60
|
70
|
+
named [70, 70, 70, 100.0], :Gray70, :Grey70
|
71
|
+
named [80, 80, 80, 100.0], :Gray80, :Grey80
|
72
|
+
named [90, 90, 90, 100.0], :Gray90, :Grey90
|
73
|
+
named [0x00, 0x80, 0x00], :Green
|
74
|
+
named [0xad, 0xff, 0x2f], :GreenYellow
|
75
|
+
named [0xf0, 0xff, 0xf0], :HoneyDew, :Honeydew
|
76
|
+
named [0xff, 0x69, 0xb4], :HotPink
|
77
|
+
named [0xcd, 0x5c, 0x5c], :IndianRed
|
78
|
+
named [0x4b, 0x00, 0x82], :Indigo
|
79
|
+
named [0xff, 0xff, 0xf0], :Ivory
|
80
|
+
named [0xf0, 0xe6, 0x8c], :Khaki
|
81
|
+
named [0xe6, 0xe6, 0xfa], :Lavender
|
82
|
+
named [0xff, 0xf0, 0xf5], :LavenderBlush
|
83
|
+
named [0x7c, 0xfc, 0x00], :LawnGreen
|
84
|
+
named [0xff, 0xfa, 0xcd], :LemonChiffon
|
85
|
+
named [0xad, 0xd8, 0xe6], :LightBlue
|
86
|
+
named [0xf0, 0x80, 0x80], :LightCoral
|
87
|
+
named [0xe0, 0xff, 0xff], :LightCyan
|
88
|
+
named [0xfa, 0xfa, 0xd2], :LightGoldenRodYellow, :LightGoldenrodYellow
|
89
|
+
named [0xd3, 0xd3, 0xd3], :LightGray, :LightGrey
|
90
|
+
named [0x90, 0xee, 0x90], :LightGreen
|
91
|
+
named [0xff, 0xb6, 0xc1], :LightPink
|
92
|
+
named [0xff, 0xa0, 0x7a], :LightSalmon, :Lightsalmon
|
93
|
+
named [0x20, 0xb2, 0xaa], :LightSeaGreen
|
94
|
+
named [0x87, 0xce, 0xfa], :LightSkyBlue
|
95
|
+
named [0x84, 0x70, 0xff], :LightSlateBlue
|
96
|
+
named [0x77, 0x88, 0x99], :LightSlateGray, :LightSlateGrey
|
97
|
+
named [0xb0, 0xc4, 0xde], :LightSteelBlue, :LightsteelBlue
|
98
|
+
named [0xff, 0xff, 0xe0], :LightYellow
|
99
|
+
named [0x00, 0xff, 0x00], :Lime
|
100
|
+
named [0x32, 0xcd, 0x32], :LimeGreen
|
101
|
+
named [0xfa, 0xf0, 0xe6], :Linen
|
102
|
+
named [0xff, 0x00, 0xff], :Magenta
|
103
|
+
named [0x80, 0x00, 0x00], :Maroon
|
104
|
+
named [0x66, 0xcd, 0xaa], :MediumAquaMarine, :MediumAquamarine
|
105
|
+
named [0x00, 0x00, 0xcd], :MediumBlue
|
106
|
+
named [0xba, 0x55, 0xd3], :MediumOrchid
|
107
|
+
named [0x93, 0x70, 0xdb], :MediumPurple
|
108
|
+
named [0x3c, 0xb3, 0x71], :MediumSeaGreen
|
109
|
+
named [0x7b, 0x68, 0xee], :MediumSlateBlue
|
110
|
+
named [0x00, 0xfa, 0x9a], :MediumSpringGreen
|
111
|
+
named [0x48, 0xd1, 0xcc], :MediumTurquoise
|
112
|
+
named [0xc7, 0x15, 0x85], :MediumVioletRed
|
113
|
+
named [0x19, 0x19, 0x70], :MidnightBlue
|
114
|
+
named [0xf5, 0xff, 0xfa], :MintCream
|
115
|
+
named [0xff, 0xe4, 0xe1], :MistyRose
|
116
|
+
named [0xff, 0xe4, 0xb5], :Moccasin
|
117
|
+
named [0xff, 0xde, 0xad], :NavajoWhite
|
118
|
+
named [0x00, 0x00, 0x80], :Navy
|
119
|
+
named [0xfd, 0xf5, 0xe6], :OldLace
|
120
|
+
named [0x80, 0x80, 0x00], :Olive
|
121
|
+
named [0x6b, 0x8e, 0x23], :OliveDrab, :Olivedrab
|
122
|
+
named [0xff, 0xa5, 0x00], :Orange
|
123
|
+
named [0xff, 0x45, 0x00], :OrangeRed
|
124
|
+
named [0xda, 0x70, 0xd6], :Orchid
|
125
|
+
named [0xee, 0xe8, 0xaa], :PaleGoldenRod, :PaleGoldenrod
|
126
|
+
named [0x98, 0xfb, 0x98], :PaleGreen
|
127
|
+
named [0xaf, 0xee, 0xee], :PaleTurquoise
|
128
|
+
named [0xdb, 0x70, 0x93], :PaleVioletRed
|
129
|
+
named [0xff, 0xef, 0xd5], :PapayaWhip
|
130
|
+
named [0xff, 0xda, 0xb9], :PeachPuff, :Peachpuff
|
131
|
+
named [0xcd, 0x85, 0x3f], :Peru
|
132
|
+
named [0xff, 0xc0, 0xcb], :Pink
|
133
|
+
named [0xdd, 0xa0, 0xdd], :Plum
|
134
|
+
named [0xb0, 0xe0, 0xe6], :PowderBlue
|
135
|
+
named [0x80, 0x00, 0x80], :Purple
|
136
|
+
named [0xff, 0x00, 0x00], :Red
|
137
|
+
named [0xbc, 0x8f, 0x8f], :RosyBrown
|
138
|
+
named [0x41, 0x69, 0xe1], :RoyalBlue
|
139
|
+
named [0x8b, 0x45, 0x13], :SaddleBrown
|
140
|
+
named [0xfa, 0x80, 0x72], :Salmon
|
141
|
+
named [0xf4, 0xa4, 0x60], :SandyBrown
|
142
|
+
named [0x2e, 0x8b, 0x57], :SeaGreen
|
143
|
+
named [0xff, 0xf5, 0xee], :SeaShell, :Seashell
|
144
|
+
named [0xa0, 0x52, 0x2d], :Sienna
|
145
|
+
named [0xc0, 0xc0, 0xc0], :Silver
|
146
|
+
named [0x87, 0xce, 0xeb], :SkyBlue
|
147
|
+
named [0x6a, 0x5a, 0xcd], :SlateBlue
|
148
|
+
named [0x70, 0x80, 0x90], :SlateGray, :SlateGrey
|
149
|
+
named [0xff, 0xfa, 0xfa], :Snow
|
150
|
+
named [0x00, 0xff, 0x7f], :SpringGreen
|
151
|
+
named [0x46, 0x82, 0xb4], :SteelBlue
|
152
|
+
named [0xd2, 0xb4, 0x8c], :Tan
|
153
|
+
named [0x00, 0x80, 0x80], :Teal
|
154
|
+
named [0xd8, 0xbf, 0xd8], :Thistle
|
155
|
+
named [0xff, 0x63, 0x47], :Tomato
|
156
|
+
named [0x40, 0xe0, 0xd0], :Turquoise
|
157
|
+
named [0xee, 0x82, 0xee], :Violet
|
158
|
+
named [0xd0, 0x20, 0x90], :VioletRed
|
159
|
+
named [0xf5, 0xde, 0xb3], :Wheat
|
160
|
+
named [0xff, 0xff, 0xff], :White
|
161
|
+
named [0xf5, 0xf5, 0xf5], :WhiteSmoke
|
162
|
+
named [0xff, 0xff, 0x00], :Yellow
|
163
|
+
named [0x9a, 0xcd, 0x32], :YellowGreen
|
164
|
+
end
|
165
|
+
|
166
|
+
require 'color/rgb/metallic'
|
data/lib/color/rgb/metallic.rb
CHANGED
@@ -1,31 +1,28 @@
|
|
1
|
-
#
|
2
|
-
module Color::RGB::Metallic
|
3
|
-
Aluminum = Color::RGB.new(0x99, 0x99, 0x99)
|
4
|
-
CoolCopper = Color::RGB.new(0xd9, 0x87, 0x19)
|
5
|
-
Copper = Color::RGB.new(0xb8, 0x73, 0x33)
|
6
|
-
Iron = Color::RGB.new(0x4c, 0x4c, 0x4c)
|
7
|
-
Lead = Color::RGB.new(0x19, 0x19, 0x19)
|
8
|
-
Magnesium = Color::RGB.new(0xb3, 0xb3, 0xb3)
|
9
|
-
Mercury = Color::RGB.new(0xe6, 0xe6, 0xe6)
|
10
|
-
Nickel = Color::RGB.new(0x80, 0x80, 0x80)
|
11
|
-
PolySilicon = Color::RGB.new(0x60, 0x00, 0x00)
|
12
|
-
Poly = PolySilicon
|
13
|
-
Silver = Color::RGB.new(0xcc, 0xcc, 0xcc)
|
14
|
-
Steel = Color::RGB.new(0x66, 0x66, 0x66)
|
15
|
-
Tin = Color::RGB.new(0x7f, 0x7f, 0x7f)
|
16
|
-
Tungsten = Color::RGB.new(0x33, 0x33, 0x33)
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
17
2
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
3
|
+
class Color::RGB
|
4
|
+
# This namespace contains some RGB metallic colours suggested by Jim
|
5
|
+
# Freeze.
|
6
|
+
module Metallic; end
|
7
|
+
|
8
|
+
class << self
|
9
|
+
private
|
10
|
+
def metallic(rgb, *names)
|
11
|
+
__named_color(Metallic, new(*rgb), *names)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
metallic [0x99, 0x99, 0x99], :Aluminum
|
16
|
+
metallic [0xd9, 0x87, 0x19], :CoolCopper
|
17
|
+
metallic [0xb8, 0x73, 0x33], :Copper
|
18
|
+
metallic [0x4c, 0x4c, 0x4c], :Iron
|
19
|
+
metallic [0x19, 0x19, 0x19], :Lead
|
20
|
+
metallic [0xb3, 0xb3, 0xb3], :Magnesium
|
21
|
+
metallic [0xe6, 0xe6, 0xe6], :Mercury
|
22
|
+
metallic [0x80, 0x80, 0x80], :Nickel
|
23
|
+
metallic [0x60, 0x00, 0x00], :PolySilicon, :Poly
|
24
|
+
metallic [0xcc, 0xcc, 0xcc], :Silver
|
25
|
+
metallic [0x66, 0x66, 0x66], :Steel
|
26
|
+
metallic [0x7f, 0x7f, 0x7f], :Tin
|
27
|
+
metallic [0x33, 0x33, 0x33], :Tungsten
|
31
28
|
end
|
data/lib/color/yiq.rb
CHANGED
@@ -1,38 +1,24 @@
|
|
1
1
|
# A colour object representing YIQ (NTSC) colour encoding.
|
2
2
|
class Color::YIQ
|
3
|
+
include Color
|
4
|
+
|
3
5
|
# Creates a YIQ colour object from fractional values 0 .. 1.
|
4
6
|
#
|
5
7
|
# Color::YIQ.new(0.3, 0.2, 0.1)
|
6
|
-
def self.from_fraction(y = 0, i = 0, q = 0)
|
7
|
-
|
8
|
-
color.y = y
|
9
|
-
color.i = i
|
10
|
-
color.q = q
|
11
|
-
color
|
8
|
+
def self.from_fraction(y = 0, i = 0, q = 0, &block)
|
9
|
+
new(y, i, q, 1.0, &block)
|
12
10
|
end
|
13
11
|
|
14
12
|
# Creates a YIQ colour object from percentages 0 .. 100.
|
15
13
|
#
|
16
14
|
# Color::YIQ.new(10, 20, 30)
|
17
|
-
def initialize(y = 0, i = 0, q = 0)
|
18
|
-
@y = y /
|
19
|
-
|
20
|
-
@q = q / 100.0
|
15
|
+
def initialize(y = 0, i = 0, q = 0, radix = 100.0, &block) # :yields self:
|
16
|
+
@y, @i, @q = [ y, i, q ].map { |v| Color.normalize(v / radix) }
|
17
|
+
block.call if block
|
21
18
|
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
# colour and a non-YIQ colour will be approximate and based on the other
|
26
|
-
# colour's #to_yiq conversion. If there is no #to_yiq conversion, this
|
27
|
-
# will raise an exception. This will report that two YIQ values are
|
28
|
-
# equivalent if all component colours are within COLOR_TOLERANCE of each
|
29
|
-
# other.
|
30
|
-
def ==(other)
|
31
|
-
other = other.to_yiq
|
32
|
-
other.kind_of?(Color::YIQ) and
|
33
|
-
((@y - other.y).abs <= Color::COLOR_TOLERANCE) and
|
34
|
-
((@i - other.i).abs <= Color::COLOR_TOLERANCE) and
|
35
|
-
((@q - other.q).abs <= Color::COLOR_TOLERANCE)
|
20
|
+
def coerce(other)
|
21
|
+
other.to_yiq
|
36
22
|
end
|
37
23
|
|
38
24
|
def to_yiq
|
@@ -69,4 +55,8 @@ class Color::YIQ
|
|
69
55
|
def inspect
|
70
56
|
"YIQ [%.2f%%, %.2f%%, %.2f%%]" % [ @y * 100, @i * 100, @q * 100 ]
|
71
57
|
end
|
58
|
+
|
59
|
+
def to_a
|
60
|
+
[ y, i, q ]
|
61
|
+
end
|
72
62
|
end
|
data/test/test_adobecolor.rb
CHANGED
data/test/test_cmyk.rb
CHANGED
data/test/test_color.rb
CHANGED
data/test/test_css.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
-
gem 'minitest'
|
2
|
-
require 'minitest/autorun'
|
3
|
-
|
4
1
|
require 'color'
|
5
2
|
require 'color/css'
|
3
|
+
require 'minitest_helper'
|
6
4
|
|
7
5
|
module TestColor
|
8
6
|
class TestCSS < Minitest::Test
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
def test_index_with_known_name
|
8
|
+
assert_same(Color::RGB::AliceBlue, Color::CSS[:aliceblue])
|
9
|
+
assert_same(Color::RGB::AliceBlue, Color::CSS["AliceBlue"])
|
10
|
+
assert_same(Color::RGB::AliceBlue, Color::CSS["aliceBlue"])
|
11
|
+
assert_same(Color::RGB::AliceBlue, Color::CSS["aliceblue"])
|
12
|
+
assert_same(Color::RGB::AliceBlue, Color::CSS[:AliceBlue])
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_index_with_unknown_name
|
16
|
+
assert_equal(nil, Color::CSS['redx'])
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
data/test/test_gimp.rb
CHANGED
data/test/test_grayscale.rb
CHANGED
data/test/test_hsl.rb
CHANGED
data/test/test_monocontrast.rb
CHANGED
data/test/test_rgb.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
require 'minitest/autorun'
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
3
2
|
|
4
3
|
require 'color'
|
4
|
+
require 'minitest_helper'
|
5
5
|
|
6
6
|
module TestColor
|
7
7
|
class TestRGB < Minitest::Test
|
@@ -254,7 +254,7 @@ module TestColor
|
|
254
254
|
end
|
255
255
|
|
256
256
|
def test_to_rgb
|
257
|
-
|
257
|
+
assert_same(Color::RGB::Black, Color::RGB::Black.to_rgb)
|
258
258
|
end
|
259
259
|
|
260
260
|
def test_to_yiq
|
@@ -278,7 +278,6 @@ module TestColor
|
|
278
278
|
end
|
279
279
|
|
280
280
|
def test_add
|
281
|
-
Color::RGB::Cyan + Color::RGB::Yellow
|
282
281
|
white = Color::RGB::Cyan + Color::RGB::Yellow
|
283
282
|
refute_nil(white)
|
284
283
|
assert_equal(Color::RGB::White, white)
|
@@ -321,6 +320,41 @@ module TestColor
|
|
321
320
|
assert_raises(ArgumentError) { Color::RGB.from_html("55555") }
|
322
321
|
end
|
323
322
|
|
323
|
+
def test_by_hex
|
324
|
+
assert_same(Color::RGB::Cyan, Color::RGB.by_hex('#0ff'))
|
325
|
+
assert_same(Color::RGB::Cyan, Color::RGB.by_hex('#00ffff'))
|
326
|
+
assert_equal("RGB [#333333]", Color::RGB.by_hex("#333").inspect)
|
327
|
+
assert_equal("RGB [#333333]", Color::RGB.by_hex("333").inspect)
|
328
|
+
assert_raises(ArgumentError) { Color::RGB.by_hex("5555555") }
|
329
|
+
assert_raises(ArgumentError) { Color::RGB.by_hex("#55555") }
|
330
|
+
assert_equal(:boom, Color::RGB.by_hex('#55555') { :boom })
|
331
|
+
end
|
332
|
+
|
333
|
+
def test_by_name
|
334
|
+
assert_same(Color::RGB::Cyan, Color::RGB.by_name('cyan'))
|
335
|
+
|
336
|
+
fetch_error = if RUBY_VERSION < "1.9"
|
337
|
+
IndexError
|
338
|
+
else
|
339
|
+
KeyError
|
340
|
+
end
|
341
|
+
|
342
|
+
assert_raises(fetch_error) { Color::RGB.by_name('cyanide') }
|
343
|
+
assert_equal(:boom, Color::RGB.by_name('cyanide') { :boom })
|
344
|
+
end
|
345
|
+
|
346
|
+
def test_by_css
|
347
|
+
assert_same(Color::RGB::Cyan, Color::RGB.by_css('#0ff'))
|
348
|
+
assert_same(Color::RGB::Cyan, Color::RGB.by_css('cyan'))
|
349
|
+
assert_raises(ArgumentError) { Color::RGB.by_css('cyanide') }
|
350
|
+
assert_equal(:boom, Color::RGB.by_css('cyanide') { :boom })
|
351
|
+
end
|
352
|
+
|
353
|
+
def test_extract_colors
|
354
|
+
assert_equal([ Color::RGB::BlanchedAlmond, Color::RGB::Cyan ],
|
355
|
+
Color::RGB.extract_colors('BlanchedAlmond is a nice shade, but #00ffff is not.'))
|
356
|
+
end
|
357
|
+
|
324
358
|
def test_inspect
|
325
359
|
assert_equal("RGB [#000000]", Color::RGB::Black.inspect)
|
326
360
|
assert_equal("RGB [#0000ff]", Color::RGB::Blue.inspect)
|