color 2.1.2 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 192b04db62242c8531c1ed8f20f9d024b5e0c57c0a97a6452d481ea5f6ca3e77
4
- data.tar.gz: c588cfff08831c11fe0e977bcc536140ee5c9c765f24be4360fad3f9e71c56cd
3
+ metadata.gz: b32b311487259ef9b4a72e7264f1eaa8a34a617918829f41b629fe814b72776f
4
+ data.tar.gz: 9fe85bc3e862e29c0fded320e03ec77063a30e86faa205c71dbae2cc6b840f28
5
5
  SHA512:
6
- metadata.gz: 0c38775facf0b320eee6b7ae6774cab01297bb63b4483fc35270f8a4e05c12ea3307bd60e0200c1dce203eb9010cfe5ab8b755a69ec5f9259fdb336a4acd34f7
7
- data.tar.gz: 1d01a276bcf0048b0ca9e2bfba6f0559fb4dbaf30c712f4cc91d9022a4da333627ffbe051cd31b3e47b4468d5018f27914984d5a77504a9901651bf0f129861f
6
+ metadata.gz: 712f80bb0eb3f8f04d6144d3ca0d608546b7bdf371b03d549aae1be985f73a8f84b7e615792206f32db8caf587e68cfb66f59c75c0ee1911d3af4d34efe0ed3f
7
+ data.tar.gz: ec2928f2caf9b5d9614168b0109d33743a542192e0ef2a30dc0d08b2dda5b5825bd539f9b5b477c1b96ffc3a37e8ebbacd57c5b71e18bd8cb9e77c023caec323
data/CHANGELOG.md CHANGED
@@ -1,12 +1,39 @@
1
1
  # color Changelog
2
2
 
3
+ ## 2.2.0 / 2026-01-DD
4
+
5
+ - When `color/rgb/colors` is loaded and the RGB color does not have defined
6
+ names, a fallback lookup to named RGB colors will be performed to use that
7
+ name.
8
+
9
+ ```ruby
10
+ simple_black = Color.from_values(r: 0, g: 0, b: 0)
11
+ stuart_black = Color.from_values(r: 0, g: 0, b: 0, names: ["semple-black-4.0"])
12
+
13
+ simple_black.name # => nil
14
+ stuart_black.name # => "semple-black-4.0"
15
+
16
+ require 'color/rgb/colors'
17
+
18
+ simple_black.name # => "black"
19
+ stuart_black.name # => "semple-black-4.0"
20
+ ```
21
+
22
+ This was suggested by [@akicho8][gh-user-akicho8] in [#89][gh-issue-89].
23
+
24
+ - The RGB inspect and pretty print formats have been modified to include defined
25
+ names. This was suggested by @akicho8 in #89.
26
+
27
+ - Added unit tests for `#pretty_print` implementations. Fixed some bugs found in
28
+ the implementations.
29
+
3
30
  ## 2.1.2 / 2025-12-30
4
31
 
5
32
  - Updated to Contributor Covenant 3.0 and applied updates to several support
6
33
  documents.
7
34
 
8
35
  - Full coverage of conversion tests. Adds CIELAB `to_yiq` and Grayscale `to_xyz`
9
- methods. Only YIQ now lacks conversions support. Fixed in [#69][pr-69].
36
+ methods. Only YIQ now lacks conversions support. Fixed in [#69][pull-69].
10
37
 
11
38
  - Fix an incorrect conversion of CIELAB colors with low lightness to XYZ, which
12
39
  caused the Y component to be ~903 times larger than correct. In practice, this
@@ -15,7 +42,7 @@
15
42
  This also affected conversion from CIELAB to RGB, CMYK, HSL, YIQ, and
16
43
  grayscale, which convert from CIELAB to XYZ as an intermediate step.
17
44
 
18
- Reported by @alexwlchan in [#95][issue-95] and fixed in [#96][pr-96].
45
+ Reported by [@alexwlchan][gh-user-alexwlchan] in [#95][issue-95] and fixed in [#96][pull-96].
19
46
 
20
47
  - Fix an incorrect comparison when converting CIE XYZ colors to RGB that could
21
48
  raise a `NoMethodError` when constructing the RGB value. The conversion
@@ -27,7 +54,7 @@
27
54
  to RGB, HSL, YIQ, and Grayscale -- all of which convert from XYZ to RGB as an
28
55
  intermediate step.
29
56
 
30
- Reported by @alexwlchan in [#92][issue-92] and fixed in [#93][pr-93].
57
+ Reported by @alexwlchan in [#92][issue-92] and fixed in [#93][pull-93].
31
58
 
32
59
  ## 2.1.1 / 2025-08-08
33
60
 
@@ -44,7 +71,7 @@ and adds more Color::XYZ white points for standard illuminants.
44
71
  was seen in `Color::RGB#to_lab` since CIELAB conversions must go through the
45
72
  XYZ color model. Even though we were using the D65 white point, the Z value
46
73
  was being clamped to 1.0 instead of the correct value of ≅1.08. Reported by
47
- @r-plus in [#45][issue-45] and fixed in [#45][pr-46].
74
+ @r-plus in [#45][issue-45] and fixed in [#45][pull-46].
48
75
 
49
76
  The resulting Color::LAB values are not _exactly_ the same values under Color
50
77
  1.8, but they are within fractional differences deemed acceptable.
@@ -128,8 +155,8 @@ this release without prior warning.
128
155
  ### 🚀 New Features
129
156
 
130
157
  - `Color::CIELAB` and `Color::XYZ` namespaces have been added. Separate
131
- implementations were submitted by David Heitzman and @stiff (in [#8][pr-8] and
132
- [#11][pr-11]), but I have reworked the code substantially. These
158
+ implementations were submitted by David Heitzman and @stiff (in [#8][pull-8]
159
+ and [#11][pull-11]), but I have reworked the code substantially. These
133
160
  implementations were originally as `Color::LAB` and include a new contrast
134
161
  calculation using the ΔE\*00 algorithm.
135
162
 
@@ -140,7 +167,7 @@ this release without prior warning.
140
167
  automated releases are enabled), full GitHub Actions, Dependabot, Standard
141
168
  Ruby, and more.
142
169
 
143
- - Charles Nutter re-added JRuby support in CI. [#36][pr-36]
170
+ - Charles Nutter re-added JRuby support in CI. [#36][pull-36]
144
171
 
145
172
  ### Governance
146
173
 
@@ -169,23 +196,22 @@ ownership to contribute it to this project under the licence terms.
169
196
  by Eric Meyer. For purposes of backwards compatibility, the previous name is
170
197
  still permitted, but its use is strongly discouraged, and it will be removed
171
198
  in the Color 2.0 release.
172
- <http://meyerweb.com/eric/thoughts/2014/06/19/rebeccapurple/>
199
+ <https://meyerweb.com/eric/thoughts/2014/06/19/rebeccapurple/>
173
200
 
174
201
  ## 1.7 / 2014-06-12
175
202
 
176
- - Added `Color::RGB::BeccaPurple` (#663399) in honour of Rebecca Meyer, the
177
- daughter of Eric Meyer, who passed away on the 7 June 2014. Her favourite
178
- color was purple. `#663399becca`
179
- <https://twitter.com/meyerweb/status/476089708674428929>
180
- <http://www.zeldman.com/2014/06/10/the-color-purple/>
181
- <http://discourse.specifiction.org/t/name-663399-becca-purple-in-css4-color/225>
203
+ - Added `Color::RGB::BeccaPurple` ([#663399][gh-issue-663399]) in honour of Rebecca Meyer, the
204
+ daughter of Eric Meyer, who passed away on 7 June 2014. Her favourite color
205
+ was purple. `#663399becca`
206
+ <https://www.zeldman.com/2014/06/10/the-color-purple/>
207
+ <https://discourse.wicg.io/t/name-663399-becca-purple-in-css4-color/225/>
182
208
 
183
209
  - Changed the homepage in the gem to point to GitHub instead of RubyForge, which
184
- has been shut down. Fixes [#10][issue-10], reported by @voxik.
210
+ has been shut down. Fixes [#10][issue-10], reported by [@voxik][gh-user-voxik].
185
211
 
186
212
  ## 1.6 / 2014-05-19
187
213
 
188
- - Aaron Hill (@armahillo) implemented the CIE Delta E 94 method by which an RGB
214
+ - Aaron Hill ([@armahillo][gh-user-armahillo]) implemented the CIE Delta E 94 method by which an RGB
189
215
  color can be asked for the closest matching color from a list of provided
190
216
  colors. Fixes [#5][issue-5].
191
217
 
@@ -220,7 +246,7 @@ ownership to contribute it to this project under the licence terms.
220
246
  this work, color classes should `include` Color only need to implement
221
247
  `#coerce(other)`, `#to_a`, and supported conversion methods (e.g., `#to_rgb`).
222
248
 
223
- - Added @daveheitzman's initial implementation of a RGB contrast method as an
249
+ - Added [@daveheitzman][gh-user-daveheitzman]'s initial implementation of a RGB contrast method as an
224
250
  extension file: `require 'color/rgb/contrast'`. This method and the value it
225
251
  returns should be considered experimental; it requires further examination to
226
252
  ensure that the results produced are consistent with the contrast comparisons
@@ -367,13 +393,25 @@ ownership to contribute it to this project under the licence terms.
367
393
  [issue-10]: https://github.com/halostatue/color/issues/10
368
394
  [issue-30]: https://github.com/halostatue/color/issues/30
369
395
  [issue-45]: https://github.com/halostatue/color/issues/45
396
+ [issue-4]: https://github.com/halostatue/color/issues/4
397
+ [issue-5]: https://github.com/halostatue/color/issues/5
370
398
  [issue-92]: https://github.com/halostatue/color/issues/92
371
399
  [issue-95]: https://github.com/halostatue/color/issues/95
372
- [pr-8]: https://github.com/halostatue/color/pulls/8
373
- [pr-11]: https://github.com/halostatue/color/pull/11
374
- [pr-36]: https://github.com/halostatue/color/pull/36
375
- [pr-46]: https://github.com/halostatue/color/pull/46
376
- [pr-69]: https://github.com/halostatue/color/pull/69
377
- [pr-93]: https://github.com/halostatue/color/pull/93
378
- [pr-96]: https://github.com/halostatue/color/pull/96
400
+ [pull-11]: https://github.com/halostatue/color/pull/11
401
+ [pull-15]: https://github.com/halostatue/color/pull/15
402
+ [pull-18]: https://github.com/halostatue/color/pull/18
403
+ [pull-24]: https://github.com/halostatue/color/pull/24
404
+ [pull-36]: https://github.com/halostatue/color/pull/36
405
+ [pull-46]: https://github.com/halostatue/color/pull/46
406
+ [pull-69]: https://github.com/halostatue/color/pull/69
407
+ [pull-8]: https://github.com/halostatue/color/pulls/8
408
+ [pull-93]: https://github.com/halostatue/color/pull/93
409
+ [pull-96]: https://github.com/halostatue/color/pull/96
379
410
  [wp-std-illuminant]: https://en.wikipedia.org/wiki/Standard_illuminant#White_points_of_standard_illuminants
411
+ [gh-user-akicho8]: https://github.com/akicho8
412
+ [gh-issue-89]: https://github.com/halostatue/color/issues/89
413
+ [gh-user-alexwlchan]: https://github.com/alexwlchan
414
+ [gh-issue-663399]: https://github.com/halostatue/color/issues/663399
415
+ [gh-user-voxik]: https://github.com/voxik
416
+ [gh-user-armahillo]: https://github.com/armahillo
417
+ [gh-user-daveheitzman]: https://github.com/daveheitzman
data/CONTRIBUTING.md CHANGED
@@ -25,7 +25,8 @@ I have several guidelines to contributing code through pull requests:
25
25
  - Use [Conventional Commits][conventional] with my
26
26
  [conventions](#commit-conventions).
27
27
 
28
- - Versions must not be updated in pull requests. This means that you must not:
28
+ - Versions must not be updated in pull requests unless otherwise directed. This
29
+ means that you must not:
29
30
 
30
31
  - Modify `VERSION` in `lib/color/version.rb`. When your patch is accepted and
31
32
  a release is made, the version will be updated at that point.
@@ -117,6 +118,6 @@ required metadata trailers are:
117
118
  [issues]: https://github.com/halostatue/color/issues
118
119
  [minitest]: https://github.com/seattlerb/minitest
119
120
  [standardrb]: https://github.com/standardrb/standard
120
- [tpope-qcm]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
121
+ [tpope-qcm]: https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
121
122
  [trailers1]: https://git-scm.com/docs/git-interpret-trailers
122
123
  [trailers2]: https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---trailerlttokengtltvaluegt
data/CONTRIBUTORS.md CHANGED
@@ -6,9 +6,12 @@
6
6
  - Thomas Sawyer
7
7
  - Aaron Hill (CIE94 color matching)
8
8
  - Luke Bennellick
9
- - @stiff (CIELAB color support)
10
- - @r-plus
9
+ - [@stiff][gh-user-stiff] (CIELAB color support)
10
+ - [@r-plus][gh-user-r-plus]
11
11
  - Matthew Draper
12
12
  - Charles Nutter
13
13
  - Paul Gallagher
14
14
  - Alex Chan
15
+
16
+ [gh-user-stiff]: https://github.com/stiff
17
+ [gh-user-r-plus]: https://github.com/r-plus
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Color -- Color Math in Ruby
2
2
 
3
+ [![RubyGems Version][shield-gems]][rubygems] ![Coveralls][shield-coveralls]
4
+ [![Build Status][shield-ci]][ci-workflow]
5
+
3
6
  - code :: <https://github.com/halostatue/color>
4
7
  - issues :: <https://github.com/halostatue/color/issues>
8
+ - docs :: <https://halostatue.github.io/color/>
5
9
  - changelog :: <https://github.com/halostatue/color/blob/main/CHANGELOG.md>
6
- - continuous integration ::
7
- [![Build Status](https://github.com/halostatue/color/actions/workflows/ci.yml/badge.svg)][ci-workflow]
8
- - test coverage ::
9
- [![Coverage](https://coveralls.io/repos/halostatue/color/badge.svg?branch=main&service=github)][coveralls]
10
10
 
11
11
  ## Description
12
12
 
@@ -22,9 +22,11 @@ reliably converted to relative color spaces (like RGB) without color profiles.
22
22
  When necessary for conversions, Color provides D65 and D50 reference white
23
23
  values in Color::XYZ.
24
24
 
25
- Color 2.1 fixes multiple Color::XYZ bugs. It builds on the Color 2.0 major
26
- release, dropping support for all versions of Ruby prior to 3.2 as well as
27
- removing or renaming a number of features. The main breaking changes are:
25
+ Color 2.2 adds a minor feature where an RGB color created from values can
26
+ silently inherit the `#name` of a predefined color if `color/rgb/colors` has
27
+ already been loaded. It builds on the Color 2.0 major release, dropping support
28
+ for all versions of Ruby prior to 3.2 as well as removing or renaming a number
29
+ of features. The main breaking changes are:
28
30
 
29
31
  - Color classes are immutable Data objects; they are no longer mutable.
30
32
  - RGB named colors are no longer loaded on gem startup, but must be required
@@ -50,5 +52,16 @@ end
50
52
  c.to_rgb
51
53
  ```
52
54
 
55
+ ## Color Semantic Versioning
56
+
57
+ The Color library uses a [Semantic Versioning][semver] scheme with one change:
58
+
59
+ - When PATCH is zero (`0`), it will be omitted from version references.
60
+
53
61
  [ci-workflow]: https://github.com/halostatue/color/actions/workflows/ci.yml
54
62
  [coveralls]: https://coveralls.io/github/halostatue/color?branch=main
63
+ [rubygems]: https://rubygems.org/gems/color
64
+ [semver]: https://semver.org/
65
+ [shield-ci]: https://img.shields.io/github/actions/workflow/status/halostatue/color/ci.yml?style=for-the-badge "Build Status"
66
+ [shield-coveralls]: https://img.shields.io/coverallsCoverage/github/halostatue/color?style=for-the-badge
67
+ [shield-gems]: https://img.shields.io/gem/v/color?style=for-the-badge "Version"
data/Rakefile CHANGED
@@ -8,7 +8,6 @@ require "minitest"
8
8
  require "minitest/test_task"
9
9
 
10
10
  Hoe.plugin :halostatue
11
- Hoe.plugin :rubygems
12
11
 
13
12
  Hoe.plugins.delete :debug
14
13
  Hoe.plugins.delete :newb
@@ -31,16 +30,16 @@ hoe = Hoe.spec "color" do
31
30
  }
32
31
 
33
32
  extra_dev_deps << ["hoe", "~> 4.0"]
34
- extra_dev_deps << ["hoe-halostatue", "~> 2.1", ">= 2.1.1"]
33
+ extra_dev_deps << ["hoe-halostatue", "~> 3.0"]
35
34
  extra_dev_deps << ["json", ">= 0.0"]
36
- extra_dev_deps << ["minitest", "~> 5.16"]
35
+ extra_dev_deps << ["minitest", "~> 6.0"]
37
36
  extra_dev_deps << ["minitest-autotest", "~> 1.0"]
38
37
  extra_dev_deps << ["minitest-focus", "~> 1.1"]
39
38
  extra_dev_deps << ["rake", ">= 10.0", "< 14"]
40
- extra_dev_deps << ["rdoc", ">= 0.0", "< 7"]
39
+ extra_dev_deps << ["rdoc", ">= 6.0", "< 8"]
41
40
  extra_dev_deps << ["simplecov", "~> 0.22"]
42
41
  extra_dev_deps << ["simplecov-lcov", "~> 0.8"]
43
- extra_dev_deps << ["standard", "~> 1.0"]
42
+ extra_dev_deps << ["standard", "~> 1.50"]
44
43
  end
45
44
 
46
45
  Minitest::TestTask.create :test
data/SECURITY.md CHANGED
@@ -25,16 +25,6 @@ Ruby 3.2 or higher.
25
25
 
26
26
  ## Reporting a Vulnerability
27
27
 
28
- Prefer creating a [private vulnerability report][advisory] with GitHub.
29
- Alternatively, send an email to [security@ruby.halostatue.ca][email] with the
30
- text `Color` in the subject. Emails sent to this address should be encrypted
31
- using [age][age] with the following public key: [age][age] with the following
32
- public key:
33
-
34
- ```
35
- age1fc6ngxmn02m62fej5cl30lrvwmxn4k3q2atqu53aatekmnqfwumqj4g93w
36
- ```
28
+ Create a [private vulnerability report][advisory] with GitHub.
37
29
 
38
30
  [advisory]: https://github.com/halostatue/color/security/advisories/new
39
- [age]: https://github.com/FiloSottile/age
40
- [email]: mailto:color@ruby.halostatue.ca
data/lib/color/cmyk.rb CHANGED
@@ -255,14 +255,13 @@ class Color::CMYK
255
255
  q.text "CMYK"
256
256
  q.breakable
257
257
  q.group 2, "[", "]" do
258
- q.text ".2f%%" % cyan
258
+ q.text "%.2f%%" % cyan
259
259
  q.fill_breakable
260
- q.text ".2f%%" % magenta
260
+ q.text "%.2f%%" % magenta
261
261
  q.fill_breakable
262
- q.text ".2f%%" % yellow
263
- q.fill_breakable
264
- q.text ".2f%%" % key
262
+ q.text "%.2f%%" % yellow
265
263
  q.fill_breakable
264
+ q.text "%.2f%%" % key
266
265
  end
267
266
  end
268
267
 
data/lib/color/hsl.rb CHANGED
@@ -98,8 +98,8 @@ class Color::HSL
98
98
  # - Saturation values <= 0 always translate to a shade of gray using luminance as
99
99
  # a percentage of gray.
100
100
  #
101
- # [1] http://bobpowell.net/RGBHSB.aspx
102
- # [2] http://support.microsoft.com/kb/29240
101
+ # [1] https://web.archive.org/web/20150311023529/http://bobpowell.net/RGBHSB.aspx
102
+ # [2] https://support.microsoft.com/kb/29240
103
103
  def to_rgb(...)
104
104
  if near_zero_or_less?(l)
105
105
  Color::RGB::Black000
data/lib/color/rgb.rb CHANGED
@@ -69,13 +69,21 @@ class Color::RGB
69
69
  ##
70
70
  # :attr_reader: name
71
71
  # The primary name for this \RGB color.
72
+ #
73
+ # If there are no defined names, the color will be checked in the name registry and if
74
+ # there's a match, it will be returned.
72
75
 
73
76
  ##
74
77
  # :attr_reader: names
75
- # The names for this \RGB color.
78
+ # The defined names for this \RGB color.
76
79
 
77
80
  ##
78
- def name = names&.first # :nodoc:
81
+ def name # :nodoc:
82
+ name = names&.first
83
+ return name if name
84
+
85
+ self.class.send(:__by_hex)[hex]&.name if defined?(Color::RGB::Metallic)
86
+ end
79
87
 
80
88
  ##
81
89
  # Coerces the other Color object into \RGB.
@@ -144,7 +152,7 @@ class Color::RGB
144
152
  ##
145
153
  # Converts \RGB to Color::HSL.
146
154
  #
147
- # The conversion here is based on formulas from http://www.easyrgb.com/math.php and
155
+ # The conversion here is based on formulas from https://www.easyrgb.com/math.php and
148
156
  # elsewhere.
149
157
  def to_hsl(...)
150
158
  min, max = [r, g, b].minmax
@@ -163,7 +171,7 @@ class Color::RGB
163
171
  end
164
172
 
165
173
  # This is based on the conversion algorithm from
166
- # http://en.wikipedia.org/wiki/HSV_color_space#Conversion_from_RGB_to_HSL_or_HSV
174
+ # https://en.wikipedia.org/wiki/HSV_color_space#Conversion_from_RGB_to_HSL_or_HSV
167
175
  # Contributed by Adam Johnson
168
176
  sixth = 1 / 6.0
169
177
  if r == max # near_zero_or_less?(r - max)
@@ -192,7 +200,7 @@ class Color::RGB
192
200
  # other \RGB color spaces are currently supported.
193
201
  #
194
202
  # :call-seq:
195
- # to_xyz(color_space: :srgb)
203
+ # to_xyz(color_space: :sRGB)
196
204
  def to_xyz(*args, **kwargs)
197
205
  color_space = kwargs[:color_space] || args.first || :sRGB
198
206
 
@@ -430,7 +438,7 @@ class Color::RGB
430
438
  def max_rgb_as_grayscale = Color::Grayscale.from_fraction([r, g, b].max)
431
439
 
432
440
  ##
433
- def inspect = "RGB [#{html}]" # :nodoc:
441
+ def inspect = names ? "RGB [#{html}] {#{names.join(" ")}}" : "RGB [#{html}]" # :nodoc:
434
442
 
435
443
  ##
436
444
  def pretty_print(q) # :nodoc:
@@ -439,6 +447,17 @@ class Color::RGB
439
447
  q.group 2, "[", "]" do
440
448
  q.text html
441
449
  end
450
+
451
+ if names
452
+ q.breakable
453
+ q.group 2, "{", "}" do
454
+ last = names.last
455
+ names.each {
456
+ q.text _1
457
+ q.fill_breakable unless _1 == last
458
+ }
459
+ end
460
+ end
442
461
  end
443
462
 
444
463
  ##
data/lib/color/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Color
4
- VERSION = "2.1.2" # :nodoc:
4
+ VERSION = "2.2.0" # :nodoc:
5
5
  end
data/lib/color/xyz.rb CHANGED
@@ -214,7 +214,7 @@ class Color::XYZ
214
214
  rel = scale(1.0 / ref.x, 1.0 / ref.y, 1.0 / ref.z)
215
215
 
216
216
  # And now transform
217
- # http://en.wikipedia.org/wiki/Lab_color_space#Forward_transformation
217
+ # https://en.wikipedia.org/wiki/Lab_color_space#Forward_transformation
218
218
  # There is a brief explanation there as far as the nature of the calculations,
219
219
  # as well as a much nicer looking modeling of the algebra.
220
220
  f = rel.map { |t|
@@ -260,7 +260,7 @@ class Color::XYZ
260
260
 
261
261
  def to_internal = [x, y, z] # :nodoc:
262
262
 
263
- def inspect = "XYZ [#{x} #{y} #{z}]" # :nodoc:
263
+ def inspect = "XYZ [%.4f %.4f %.4f]" % [x, y, z] # :nodoc:
264
264
 
265
265
  def pretty_print(q) # :nodoc:
266
266
  q.text "XYZ"
data/lib/color/yiq.rb CHANGED
@@ -88,15 +88,15 @@ class Color::YIQ
88
88
 
89
89
  def inspect = "YIQ [%.2f%% %.2f%% %.2f%%]" % [y * 100, i * 100, q * 100] # :nodoc:
90
90
 
91
- def pretty_print(q) # :nodoc:
92
- q.text "YIQ"
93
- q.breakable
94
- q.group 2, "[", "]" do
95
- q.text "%.2f%%" % y
96
- q.fill_breakable
97
- q.text "%.2f%%" % i
98
- q.fill_breakable
99
- q.text "%.2f%%" % q
91
+ def pretty_print(pq) # :nodoc:
92
+ pq.text "YIQ"
93
+ pq.breakable
94
+ pq.group 2, "[", "]" do
95
+ pq.text "%.2f%%" % (y * 100)
96
+ pq.fill_breakable
97
+ pq.text "%.2f%%" % (i * 100)
98
+ pq.fill_breakable
99
+ pq.text "%.2f%%" % (q * 100)
100
100
  end
101
101
  end
102
102
 
@@ -3,6 +3,8 @@
3
3
  require "color"
4
4
  require "color/rgb/colors"
5
5
 
6
+ require "pp"
7
+
6
8
  gem "minitest"
7
9
  require "minitest/autorun"
8
10
  require "minitest/focus"
@@ -18,5 +20,11 @@ module Minitest::ColorExtensions
18
20
  assert_in_delta expected, actual, Color::TOLERANCE, msg
19
21
  end
20
22
 
23
+ def assert_pretty_inspect(expected, object, msg = nil)
24
+ actual = PP.pp(object, +"", 8)
25
+
26
+ assert_equal expected, actual, message(msg, nil) { diff expected, actual }
27
+ end
28
+
21
29
  Minitest::Test.send(:include, self)
22
30
  end
data/test/test_cmyk.rb CHANGED
@@ -34,6 +34,10 @@ module TestColor
34
34
  assert_equal("CMYK [10.00% 20.00% 30.00% 40.00%]", @cmyk.inspect)
35
35
  end
36
36
 
37
+ def test_pretty_print
38
+ assert_pretty_inspect "CMYK\n[10.00%\n 20.00%\n 30.00%\n 40.00%]\n", @cmyk
39
+ end
40
+
37
41
  def test_css
38
42
  assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00%, rgb(54.00% 48.00% 42.00%))", @cmyk.css)
39
43
  assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00% / 0.50, rgb(54.00% 48.00% 42.00% / 0.50))", @cmyk.css(alpha: 0.5))
@@ -42,6 +42,10 @@ module TestColor
42
42
  def test_inspect
43
43
  assert_equal("Grayscale [33.00%]", @gs.inspect)
44
44
  end
45
+
46
+ def test_pretty_print
47
+ assert_pretty_inspect "Grayscale\n[33.00%]\n", @gs
48
+ end
45
49
  end
46
50
 
47
51
  class TestGrayscaleConversions < Minitest::Test
data/test/test_hsl.rb CHANGED
@@ -82,6 +82,10 @@ module TestColor
82
82
  def test_inspect
83
83
  assert_equal "HSL [145.00deg 20.00% 30.00%]", @hsl.inspect
84
84
  end
85
+
86
+ def test_pretty_print
87
+ assert_pretty_inspect "HSL\n[145.00deg\n 20.00%\n 30.00%]\n", @hsl
88
+ end
85
89
  end
86
90
 
87
91
  class TestHSLConversions < Minitest::Test
data/test/test_rgb.rb CHANGED
@@ -139,8 +139,8 @@ module TestColor
139
139
  def test_by_hex
140
140
  assert_same(Color::RGB::Cyan, Color::RGB.by_hex("#0ff"))
141
141
  assert_same(Color::RGB::Cyan, Color::RGB.by_hex("#00ffff"))
142
- assert_equal("RGB [#333333]", Color::RGB.by_hex("#333").inspect)
143
- assert_equal("RGB [#333333]", Color::RGB.by_hex("333").inspect)
142
+ assert_equal("RGB [#333333] {tungsten}", Color::RGB.by_hex("#333").inspect)
143
+ assert_equal("RGB [#333333] {tungsten}", Color::RGB.by_hex("333").inspect)
144
144
  assert_raises(ArgumentError) { Color::RGB.by_hex("5555555") }
145
145
  assert_raises(ArgumentError) { Color::RGB.by_hex("#55555") }
146
146
  end
@@ -170,11 +170,41 @@ module TestColor
170
170
  end
171
171
 
172
172
  def test_inspect
173
- assert_equal("RGB [#000000]", Color::RGB::Black.inspect)
174
- assert_equal("RGB [#0000ff]", Color::RGB::Blue.inspect)
175
- assert_equal("RGB [#00ff00]", Color::RGB::Lime.inspect)
176
- assert_equal("RGB [#ff0000]", Color::RGB::Red.inspect)
177
- assert_equal("RGB [#ffffff]", Color::RGB::White.inspect)
173
+ assert_equal("RGB [#000000] {black}", Color::RGB::Black.inspect)
174
+ assert_equal("RGB [#0000ff] {blue}", Color::RGB::Blue.inspect)
175
+ assert_equal("RGB [#00ff00] {lime}", Color::RGB::Lime.inspect)
176
+ assert_equal("RGB [#ff0000] {red}", Color::RGB::Red.inspect)
177
+ assert_equal("RGB [#ffffff] {white}", Color::RGB::White.inspect)
178
+ assert_equal("RGB [#708090] {slategray slategrey}", Color::RGB::SlateGrey.inspect)
179
+ end
180
+
181
+ def test_pretty_print
182
+ assert_pretty_inspect("RGB\n[#000000]\n{black}\n", Color::RGB::Black)
183
+ assert_pretty_inspect("RGB\n[#0000ff]\n{blue}\n", Color::RGB::Blue)
184
+ assert_pretty_inspect("RGB\n[#00ff00]\n{lime}\n", Color::RGB::Lime)
185
+ assert_pretty_inspect("RGB\n[#ff0000]\n{red}\n", Color::RGB::Red)
186
+ assert_pretty_inspect("RGB\n[#ffffff]\n{white}\n", Color::RGB::White)
187
+ assert_pretty_inspect("RGB\n[#708090]\n{slategray\n slategrey}\n", Color::RGB::SlateGrey)
188
+ end
189
+
190
+ def test_name
191
+ assert_equal("black", Color::RGB::Black.name)
192
+ assert_equal("blue", Color::RGB::Blue.name)
193
+ assert_equal("lime", Color::RGB::Lime.name)
194
+ assert_equal("red", Color::RGB::Red.name)
195
+ assert_equal("white", Color::RGB::White.name)
196
+
197
+ assert_equal("black", Color::RGB.from_values(0, 0, 0).name)
198
+ assert_equal("blue", Color::RGB.from_values(0, 0, 0xff).name)
199
+ assert_equal("lime", Color::RGB.from_values(0, 0xff, 0).name)
200
+ assert_equal("red", Color::RGB.from_values(0xff, 0, 0).name)
201
+ assert_equal("white", Color::RGB.from_values(0xff, 0xff, 0xff).name)
202
+
203
+ assert_equal("000", Color::RGB.from_values(0, 0, 0, ["000"]).name)
204
+ assert_equal("00f", Color::RGB.from_values(0, 0, 0xff, ["00f"]).name)
205
+ assert_equal("0f0", Color::RGB.from_values(0, 0xff, 0, ["0f0"]).name)
206
+ assert_equal("f00", Color::RGB.from_values(0xff, 0, 0, ["f00"]).name)
207
+ assert_equal("fff", Color::RGB.from_values(0xff, 0xff, 0xff, ["fff"]).name)
178
208
  end
179
209
 
180
210
  def test_delta_e2000
data/test/test_yiq.rb CHANGED
@@ -31,6 +31,10 @@ module TestColor
31
31
  def test_inspect
32
32
  assert_equal("YIQ [10.00% 20.00% 30.00%]", @yiq.inspect)
33
33
  end
34
+
35
+ def test_pretty_print
36
+ assert_pretty_inspect "YIQ\n[10.00%\n 20.00%\n 30.00%]\n", @yiq
37
+ end
34
38
  end
35
39
 
36
40
  class TestYIQConversions < Minitest::Test
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin Ziegler
8
8
  - Matt Lyon
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 1970-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hoe
@@ -30,20 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.1'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 2.1.1
33
+ version: '3.0'
37
34
  type: :development
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
- version: '2.1'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 2.1.1
40
+ version: '3.0'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: json
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -64,14 +58,14 @@ dependencies:
64
58
  requirements:
65
59
  - - "~>"
66
60
  - !ruby/object:Gem::Version
67
- version: '5.16'
61
+ version: '6.0'
68
62
  type: :development
69
63
  prerelease: false
70
64
  version_requirements: !ruby/object:Gem::Requirement
71
65
  requirements:
72
66
  - - "~>"
73
67
  - !ruby/object:Gem::Version
74
- version: '5.16'
68
+ version: '6.0'
75
69
  - !ruby/object:Gem::Dependency
76
70
  name: minitest-autotest
77
71
  requirement: !ruby/object:Gem::Requirement
@@ -126,20 +120,20 @@ dependencies:
126
120
  requirements:
127
121
  - - ">="
128
122
  - !ruby/object:Gem::Version
129
- version: '0.0'
123
+ version: '6.0'
130
124
  - - "<"
131
125
  - !ruby/object:Gem::Version
132
- version: '7'
126
+ version: '8'
133
127
  type: :development
134
128
  prerelease: false
135
129
  version_requirements: !ruby/object:Gem::Requirement
136
130
  requirements:
137
131
  - - ">="
138
132
  - !ruby/object:Gem::Version
139
- version: '0.0'
133
+ version: '6.0'
140
134
  - - "<"
141
135
  - !ruby/object:Gem::Version
142
- version: '7'
136
+ version: '8'
143
137
  - !ruby/object:Gem::Dependency
144
138
  name: simplecov
145
139
  requirement: !ruby/object:Gem::Requirement
@@ -174,14 +168,14 @@ dependencies:
174
168
  requirements:
175
169
  - - "~>"
176
170
  - !ruby/object:Gem::Version
177
- version: '1.0'
171
+ version: '1.50'
178
172
  type: :development
179
173
  prerelease: false
180
174
  version_requirements: !ruby/object:Gem::Requirement
181
175
  requirements:
182
176
  - - "~>"
183
177
  - !ruby/object:Gem::Version
184
- version: '1.0'
178
+ version: '1.50'
185
179
  description: |-
186
180
  Color is a Ruby library to provide RGB, CMYK, HSL, and other color space
187
181
  manipulation support to applications that require it. It provides optional named
@@ -195,9 +189,11 @@ description: |-
195
189
  When necessary for conversions, Color provides D65 and D50 reference white
196
190
  values in Color::XYZ.
197
191
 
198
- Color 2.1 fixes multiple Color::XYZ bugs. It builds on the Color 2.0 major
199
- release, dropping support for all versions of Ruby prior to 3.2 as well as
200
- removing or renaming a number of features. The main breaking changes are:
192
+ Color 2.2 adds a minor feature where an RGB color created from values can
193
+ silently inherit the `#name` of a predefined color if `color/rgb/colors` has
194
+ already been loaded. It builds on the Color 2.0 major release, dropping support
195
+ for all versions of Ruby prior to 3.2 as well as removing or renaming a number
196
+ of features. The main breaking changes are:
201
197
 
202
198
  - Color classes are immutable Data objects; they are no longer mutable.
203
199
  - RGB named colors are no longer loaded on gem startup, but must be required
@@ -255,6 +251,7 @@ licenses:
255
251
  metadata:
256
252
  source_code_uri: https://github.com/halostatue/color
257
253
  bug_tracker_uri: https://github.com/halostatue/color/issues
254
+ documentation_uri: https://halostatue.github.io/color/
258
255
  changelog_uri: https://github.com/halostatue/color/blob/main/CHANGELOG.md
259
256
  rubygems_mfa_required: 'true'
260
257
  rdoc_options:
@@ -273,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
273
270
  - !ruby/object:Gem::Version
274
271
  version: '0'
275
272
  requirements: []
276
- rubygems_version: 3.6.9
273
+ rubygems_version: 4.0.4
277
274
  specification_version: 4
278
275
  summary: Color is a Ruby library to provide RGB, CMYK, HSL, and other color space
279
276
  manipulation support to applications that require it