color_namer_ruby 0.1.1 → 0.1.2

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: 99e55c151479cf0f2bdccedd02fe6e5632bf4cc2becc0c6bb35df9396429f53e
4
- data.tar.gz: c1ed71d2712b45c0ec8174c8049995aceb5faeaf3a8552f108676e03c3b43156
3
+ metadata.gz: de06760f8ad6bed10d51aa558ac1c5eec436bb432d11e338020d293ce900516b
4
+ data.tar.gz: 9997efc3fb2e420b357d03d23f032df939019476d560759def9c316a93a76213
5
5
  SHA512:
6
- metadata.gz: 598275d62f010ac8d7914644d284c7eee421509b8e3f38b98542adc0521037301ae092b87b986f11faac30cece71f2322ffcc9244d1ea29aa242061e1738e329
7
- data.tar.gz: 29a288b098fa9de4f119b7a4b55a97bee14bf4a4cb47f7a18df9344ed801ed8df5859aa5b41f715edaad3fc59c54a394c1b5cc857c3bec97003fd73ce93bfd5c
6
+ metadata.gz: 1b26c67fcaf715ef105c2e38515ad54088af31edc2a4bbd0fabd2af160b55b7324594e055b527249eeefa0ec23103878fba08de05a69525f529bbc4862c7dcb9
7
+ data.tar.gz: 947105f26f503f32a92aca9a381787dac3553ef8ea50c0e6043b4049975c24ccee2d1c582f5b0a6502da7145ce306915d4f4fdbaaba2ff7ab7f296aa75b4cac5
data/README.md CHANGED
@@ -12,14 +12,8 @@ Mike Bostock of [D3](http://d3js.org/) fame [explains it well](https://gist.gith
12
12
 
13
13
  ## Lists
14
14
 
15
- The color names are derived from several lists:
16
-
17
- - [roygbiv](lib/color_namer_rails/roygbiv.rb)
18
- - [basic](lib/color_namer_rails/basic.rb)
19
- - [html](lib/color_namer_rails/html.rb) - the HTML color names.
20
- - [x11](lib/color_namer_rails/x11.rb) - The list that preceded the HTML color names
21
- - [pantone](lib/color_namer_rails/pantone.rb)
22
- - [ntc](lib/color_namer_rails/ntc.rb), an [astounding collection](http://chir.ag/projects/ntc/) of over 1500 named colors.
15
+ The color names are derived from several lists in the [ColorSwatchCollection gem](https://github.com/louiswdavis/color_swatch_collection).
16
+ Because of the number of swatches, if you put in a "basic" colour like "blue" there are many interpretations across the lists of what that colour should be so it may not match your expectation.
23
17
 
24
18
  ## Installation
25
19
 
@@ -55,7 +49,7 @@ Get a list of the colour collections that can be checked against.
55
49
 
56
50
  ```ruby
57
51
  ColorNamerRuby.list_collections
58
- => ['basic', 'html', 'ntc', 'pantone', 'roygbiv', 'x11']
52
+ => ["basic", "html", "ntc", "pantone", "roygbiv", "x11", "tailwind_v1", "tailwind_v2", "tailwind_v3", "tailwind_v4"]
59
53
  ```
60
54
 
61
55
  Get a single name for a colour using `.get_name` by passing a colour in a way that [ColorConversion]((https://github.com/devrieda/color_conversion)) accepts.
@@ -63,31 +57,31 @@ When passing colours with their properties assigned to keys, you need to pass ni
63
57
 
64
58
  ```ruby
65
59
  ColorNamerRuby.get_name('#3672b4')
66
- => ['azure']
60
+ => ["blue-700"]
67
61
 
68
62
  ColorNamerRuby.get_name('', r: 70, g: 130, b: 180, a: 0.5)
69
- => ['steelblue']
63
+ => ["steelblue"]
70
64
 
71
65
  ColorNamerRuby.get_name('', r: 130, g: 180, b: 70)
72
- => ['sushi']
66
+ => ["sushi"]
73
67
 
74
68
  ColorNamerRuby.get_name('', h: 20, s: 73, l: 20)
75
- => ['cioccolato']
69
+ => ["cioccolato"]
76
70
 
77
71
  ColorNamerRuby.get_name(nil, h: 107, s: 61, v: 71)
78
- => ['apple']
72
+ => ["apple"]
79
73
 
80
74
  ColorNamerRuby.get_name(nil, h: 61, s: 71, b: 32)
81
- => ['camouflage']
75
+ => ["camouflage"]
82
76
 
83
77
  ColorNamerRuby.get_name(nil, c: 71, m: 15, y: 5, k: 54)
84
- => ['blue dianne']
78
+ => ["blue dianne"]
85
79
 
86
80
  ColorNamerRuby.get_name('rgb(51, 102, 204)')
87
- => ['denim']
81
+ => ["denim"]
88
82
 
89
83
  ColorNamerRuby.get_name('hsl(225, 73%, 57%)')
90
- => ['royalblue']
84
+ => ["royalblue"]
91
85
  ```
92
86
 
93
87
  Get a list of colour names sorted by their perceptual similarity to the given color by using `.get_names`.
@@ -95,7 +89,7 @@ Again, when passing colours with their properties assigned to keys, you need to
95
89
 
96
90
  ```ruby
97
91
  ColorNamerRuby.get_names('#3672b4')
98
- => ['azure', 'st tropaz', 'denim', 'steelblue', ...]
92
+ => ["blue-700", "azure", "blue-600", "st tropaz", "denim", "steelblue", ...]
99
93
  ```
100
94
 
101
95
  Get a list of all the colour names across the lists that can be checked against.
@@ -111,7 +105,7 @@ When passing colours with their properties assigned to keys, you need to pass ni
111
105
 
112
106
  ```ruby
113
107
  ColorNamerRuby.get_colour('#3672b4')
114
- => [{ distance: 8.660254037844387, hex: '#315BA1', name: 'azure' }]
108
+ => [{ distance: 7.615773105863909, hex: "#2B6CB0", name: "blue-700" }]
115
109
  ```
116
110
 
117
111
  Get a list of colour hashes sorted by their perceptual similarity to the given color by using `.get_colours`.
@@ -120,9 +114,11 @@ Again, when passing colours with their properties assigned to keys, you need to
120
114
  ```ruby
121
115
  ColorNamerRuby.get_colours('#3672b4')
122
116
  => [
123
- => { distance: 8.660254037844387, hex: '#315BA1', name: 'azure' },
124
- => { distance: 9.9498743710662, hex: '#2D569B', name: 'st tropaz' },
125
- => { distance: 10.81665382639196, name: 'denim' },
117
+ => { distance: 7.615773105863909, hex: "#2B6CB0", name: "blue-700" },
118
+ => { distance: 8.660254037844387, hex: "#315BA1", name: "azure" },
119
+ => { distance: 9.16515138991168, hex: "#3182CE", name: "blue-600" },
120
+ => { distance: 9.9498743710662, hex: "#2D569B", name: "st tropaz" },
121
+ => { distance: 10.816653826391969, hex: "#2B6CC4", name: "denim" },
126
122
  => .
127
123
  => .
128
124
  => .
@@ -152,6 +148,7 @@ It can be used for `get_name`, `get_names`, `get_all_names`, or `get_colour`, `g
152
148
 
153
149
  ```ruby
154
150
  ColorNamerRuby.get_names('#3672b4', pick: ['basic', 'x11'])
151
+ => ["steelblue", "royalblue", "cornflowerblue", "lightsteelblue", "mediumturquoise", ...]
155
152
  ```
156
153
 
157
154
  ### omit
@@ -160,7 +157,8 @@ The opposite of `options.pick`.
160
157
  It can be used for `get_name`, `get_names`, `get_all_names`, or `get_colour`, `get_colours`, `get_all_colours`.
161
158
 
162
159
  ```ruby
163
- ColorNamerRuby.get_names('#3672b4', omit: ['pantone', 'roygbiv'])
160
+ ColorNamerRuby.get_names('#3672b4', omit: ['pantone', 'roygbiv', 'tailwind_v1'])
161
+ => ["azure", "st tropaz", "steelblue", "steelblue", "steel blue", ...]
164
162
  ```
165
163
 
166
164
  ### limit
@@ -169,7 +167,8 @@ This option allows us to limit the number of names that are returned to keep the
169
167
  It can be used for `get_names`, or `get_colours` (since `get_name` and `get_colour` already have a limit of 1).
170
168
 
171
169
  ```ruby
172
- ColorNamerRuby.get_names('#3672b4', limit: 5)
170
+ ColorNamerRuby.get_names('#3672b4', limit: 3)
171
+ => ["blue-700", "azure", "blue-600"]
173
172
  ```
174
173
 
175
174
  ###
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'color_conversion'
4
4
  require 'active_support/core_ext/object/blank'
5
+ require 'active_support/core_ext/string/inflections'
5
6
 
6
7
  module ColorNamerRuby
7
8
  class Distance
@@ -13,7 +14,7 @@ module ColorNamerRuby
13
14
  ColorNamerRuby.list_collections.each do |collection_name|
14
15
  next unless (pick.empty? || pick.include?(collection_name)) && !omit.include?(collection_name)
15
16
 
16
- colour_lists += self.get_colour_distances_in_list(Object.const_get("ColorSwatchCollection::#{collection_name.capitalize}").colours)
17
+ colour_lists += self.get_colour_distances_in_list(Object.const_get("ColorSwatchCollection::#{collection_name.classify}").colours)
17
18
  end
18
19
 
19
20
  colour_lists = colour_lists.flatten.compact.reject(&:empty?)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ColorNamerRuby
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -1,70 +1,70 @@
1
- # frozen_string_literal: true
2
-
3
- require 'color_swatch_collection'
4
-
5
- require_relative 'color_namer_ruby/version'
6
- require_relative 'color_namer_ruby/distance'
7
-
8
- module ColorNamerRuby
9
- class Error < StandardError; end
10
-
11
- def self.list_collections
12
- ColorSwatchCollection.list_collections
13
- end
14
-
15
- def self.get_name(colour_value, pick: [], omit: [], **alt_colour_value)
16
- self.get_colour(colour_value, pick: pick, omit: omit, **alt_colour_value).map { |h| h[:name] } || []
17
- end
18
-
19
- def self.get_names(colour_value, pick: [], omit: [], limit: -1, **alt_colour_value)
20
- self.get_colours(colour_value, pick: pick, omit: omit, limit: limit, **alt_colour_value).map { |h| h[:name] } || []
21
- end
22
-
23
- def self.get_all_names(pick: [], omit: [])
24
- self.get_all_colours(pick: pick, omit: omit).map { |h| h[:name] } || []
25
- end
26
-
27
- def self.get_colour(colour_value, pick: [], omit: [], **alt_colour_value)
28
- # alt_colour_value are used to collect colour paramaters when they are passed in the key format
29
- hex = ColorConversion::Color.new(colour_value.presence || alt_colour_value).hex
30
-
31
- # if we get an exact match, return it
32
- colour = self.get_colour_from_collections(hex, pick, omit)
33
-
34
- if colour.present?
35
- colour[:distance] = 0.0
36
- return [colour]
37
- end
38
-
39
- # if we don't get an exact match, try to find the closest match
40
- ColorNamerRuby::Distance.get_names_from_hex(hex, pick, omit, 1)
41
- end
42
-
43
- def self.get_colours(colour_value, pick: [], omit: [], limit: -1, **alt_colour_value)
44
- hex = ColorConversion::Color.new(colour_value.presence || alt_colour_value).hex
45
-
46
- # get the closest matches up to the count limit
47
- ColorNamerRuby::Distance.get_names_from_hex(hex, pick, omit, limit)
48
- end
49
-
50
- # if the same names appear in multiple lists, they could still appear even if certain lists they are in are omitted
51
- def self.get_all_colours(pick: [], omit: [])
52
- ColorSwatchCollection.get_colours(pick: pick, omit: omit)
53
- end
54
-
55
- private
56
-
57
- def self.get_colour_from_collections(hex, pick, omit)
58
- colour = nil
59
-
60
- self.list_collections.each do |collection_name|
61
- next unless (pick.empty? || pick.include?(collection_name)) && !omit.include?(collection_name)
62
-
63
- colour = ColorSwatchCollection.get_from_hex(hex, pick: [collection_name])
64
-
65
- break if colour.present?
66
- end
67
-
68
- colour || {}
69
- end
70
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'color_swatch_collection'
4
+
5
+ require_relative 'color_namer_ruby/version'
6
+ require_relative 'color_namer_ruby/distance'
7
+
8
+ module ColorNamerRuby
9
+ class Error < StandardError; end
10
+
11
+ def self.list_collections
12
+ ColorSwatchCollection.list_collections
13
+ end
14
+
15
+ def self.get_name(colour_value, pick: [], omit: [], **alt_colour_value)
16
+ self.get_colour(colour_value, pick: pick, omit: omit, **alt_colour_value).map { |h| h[:name] } || []
17
+ end
18
+
19
+ def self.get_names(colour_value, pick: [], omit: [], limit: -1, **alt_colour_value)
20
+ self.get_colours(colour_value, pick: pick, omit: omit, limit: limit, **alt_colour_value).map { |h| h[:name] } || []
21
+ end
22
+
23
+ def self.get_all_names(pick: [], omit: [])
24
+ self.get_all_colours(pick: pick, omit: omit).map { |h| h[:name] } || []
25
+ end
26
+
27
+ def self.get_colour(colour_value, pick: [], omit: [], **alt_colour_value)
28
+ # alt_colour_value are used to collect colour paramaters when they are passed in the key format
29
+ hex = ColorConversion::Color.new(colour_value.presence || alt_colour_value).hex
30
+
31
+ # if we get an exact match, return it
32
+ colour = self.get_colour_from_collections(hex, pick, omit)
33
+
34
+ if colour.present?
35
+ colour[:distance] = 0.0
36
+ return [colour]
37
+ end
38
+
39
+ # if we don't get an exact match, try to find the closest match
40
+ ColorNamerRuby::Distance.get_names_from_hex(hex, pick, omit, 1)
41
+ end
42
+
43
+ def self.get_colours(colour_value, pick: [], omit: [], limit: -1, **alt_colour_value)
44
+ hex = ColorConversion::Color.new(colour_value.presence || alt_colour_value).hex
45
+
46
+ # get the closest matches up to the count limit
47
+ ColorNamerRuby::Distance.get_names_from_hex(hex, pick, omit, limit)
48
+ end
49
+
50
+ # if the same names appear in multiple lists, they could still appear even if certain lists they are in are omitted
51
+ def self.get_all_colours(pick: [], omit: [])
52
+ ColorSwatchCollection.get_colours(pick: pick, omit: omit)
53
+ end
54
+
55
+ private
56
+
57
+ def self.get_colour_from_collections(hex, pick, omit)
58
+ colour = nil
59
+
60
+ self.list_collections.each do |collection_name|
61
+ next unless (pick.empty? || pick.include?(collection_name)) && !omit.include?(collection_name)
62
+
63
+ colour = ColorSwatchCollection.get_from_hex(hex, pick: [collection_name])
64
+
65
+ break if colour.present?
66
+ end
67
+
68
+ colour || {}
69
+ end
70
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_namer_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Louis Davis
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-08-19 00:00:00.000000000 Z
10
+ date: 2025-08-30 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -43,14 +43,14 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.1.0
46
+ version: 0.1.1
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: 0.1.0
53
+ version: 0.1.1
54
54
  description: Provide a color in a variety of formats and get a name back based on
55
55
  a range of colour options and see how closely they match your color.
56
56
  email: