color_namer_ruby 0.1.0 → 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 +4 -4
- data/README.md +92 -43
- data/Rakefile +2 -2
- data/lib/color_namer_ruby/distance.rb +45 -44
- data/lib/color_namer_ruby/version.rb +5 -5
- data/lib/color_namer_ruby.rb +62 -10
- metadata +21 -14
- data/lib/color_namer_ruby/basic.rb +0 -36
- data/lib/color_namer_ruby/html.rb +0 -163
- data/lib/color_namer_ruby/namer.rb +0 -44
- data/lib/color_namer_ruby/ntc.rb +0 -1580
- data/lib/color_namer_ruby/pantone.rb +0 -134
- data/lib/color_namer_ruby/roygbiv.rb +0 -21
- data/lib/color_namer_ruby/x11.rb +0 -159
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de06760f8ad6bed10d51aa558ac1c5eec436bb432d11e338020d293ce900516b
|
4
|
+
data.tar.gz: 9997efc3fb2e420b357d03d23f032df939019476d560759def9c316a93a76213
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
@@ -37,60 +31,112 @@ gem install color_name_ruby
|
|
37
31
|
|
38
32
|
## Usage
|
39
33
|
|
34
|
+
## Methods
|
35
|
+
|
36
|
+
Possible methods:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
ColorNamerRuby.list_collections
|
40
|
+
ColorNamerRuby.get_name
|
41
|
+
ColorNamerRuby.get_names
|
42
|
+
ColorNamerRuby.get_all_names
|
43
|
+
ColorNamerRuby.get_colour
|
44
|
+
ColorNamerRuby.get_colours
|
45
|
+
ColorNamerRuby.get_all_colours
|
46
|
+
```
|
47
|
+
|
48
|
+
Get a list of the colour collections that can be checked against.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
ColorNamerRuby.list_collections
|
52
|
+
=> ["basic", "html", "ntc", "pantone", "roygbiv", "x11", "tailwind_v1", "tailwind_v2", "tailwind_v3", "tailwind_v4"]
|
53
|
+
```
|
54
|
+
|
40
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.
|
41
56
|
When passing colours with their properties assigned to keys, you need to pass nil or an empty string as the first parameter.
|
42
57
|
|
43
58
|
```ruby
|
44
|
-
ColorNamerRuby
|
45
|
-
=>
|
59
|
+
ColorNamerRuby.get_name('#3672b4')
|
60
|
+
=> ["blue-700"]
|
46
61
|
|
47
|
-
ColorNamerRuby
|
48
|
-
=>
|
62
|
+
ColorNamerRuby.get_name('', r: 70, g: 130, b: 180, a: 0.5)
|
63
|
+
=> ["steelblue"]
|
49
64
|
|
50
|
-
ColorNamerRuby
|
51
|
-
=>
|
65
|
+
ColorNamerRuby.get_name('', r: 130, g: 180, b: 70)
|
66
|
+
=> ["sushi"]
|
52
67
|
|
53
|
-
ColorNamerRuby
|
54
|
-
=>
|
68
|
+
ColorNamerRuby.get_name('', h: 20, s: 73, l: 20)
|
69
|
+
=> ["cioccolato"]
|
55
70
|
|
56
|
-
ColorNamerRuby
|
57
|
-
=>
|
71
|
+
ColorNamerRuby.get_name(nil, h: 107, s: 61, v: 71)
|
72
|
+
=> ["apple"]
|
58
73
|
|
59
|
-
ColorNamerRuby
|
60
|
-
=>
|
74
|
+
ColorNamerRuby.get_name(nil, h: 61, s: 71, b: 32)
|
75
|
+
=> ["camouflage"]
|
61
76
|
|
62
|
-
ColorNamerRuby
|
63
|
-
=>
|
77
|
+
ColorNamerRuby.get_name(nil, c: 71, m: 15, y: 5, k: 54)
|
78
|
+
=> ["blue dianne"]
|
64
79
|
|
65
|
-
ColorNamerRuby
|
66
|
-
=>
|
80
|
+
ColorNamerRuby.get_name('rgb(51, 102, 204)')
|
81
|
+
=> ["denim"]
|
67
82
|
|
68
|
-
ColorNamerRuby
|
69
|
-
=>
|
83
|
+
ColorNamerRuby.get_name('hsl(225, 73%, 57%)')
|
84
|
+
=> ["royalblue"]
|
70
85
|
```
|
71
86
|
|
72
87
|
Get a list of colour names sorted by their perceptual similarity to the given color by using `.get_names`.
|
73
88
|
Again, when passing colours with their properties assigned to keys, you need to pass nil or an empty string as the first parameter.
|
74
89
|
|
75
90
|
```ruby
|
76
|
-
ColorNamerRuby
|
91
|
+
ColorNamerRuby.get_names('#3672b4')
|
92
|
+
=> ["blue-700", "azure", "blue-600", "st tropaz", "denim", "steelblue", ...]
|
93
|
+
```
|
94
|
+
|
95
|
+
Get a list of all the colour names across the lists that can be checked against.
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
ColorNamerRuby.get_all_names
|
99
|
+
=> ['black', 'blue', 'cyan', 'green', 'teal', ...]
|
100
|
+
```
|
101
|
+
|
102
|
+
You can also get the entire swatch object(s) to view the hex values and distance the colours are from the source colour you provided. These methods are all related/similar to their 'name' named method counterparts, except they provide the colour hash instead of just the name, and can be called in a similar way too.
|
103
|
+
|
104
|
+
When passing colours with their properties assigned to keys, you need to pass nil or an empty string as the first parameter.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
ColorNamerRuby.get_colour('#3672b4')
|
108
|
+
=> [{ distance: 7.615773105863909, hex: "#2B6CB0", name: "blue-700" }]
|
109
|
+
```
|
110
|
+
|
111
|
+
Get a list of colour hashes sorted by their perceptual similarity to the given color by using `.get_colours`.
|
112
|
+
Again, when passing colours with their properties assigned to keys, you need to pass nil or an empty string as the first parameter.
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
ColorNamerRuby.get_colours('#3672b4')
|
77
116
|
=> [
|
78
|
-
=> {
|
79
|
-
=> {
|
80
|
-
=> {
|
81
|
-
=> {
|
82
|
-
=> {
|
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" },
|
83
122
|
=> .
|
84
123
|
=> .
|
85
124
|
=> .
|
86
125
|
=> ]
|
87
126
|
```
|
88
127
|
|
89
|
-
Get a list of the colour lists that can be checked against.
|
128
|
+
Get a list of all the colour hashes across the lists that can be checked against.
|
90
129
|
|
91
130
|
```ruby
|
92
|
-
ColorNamerRuby
|
93
|
-
=> [
|
131
|
+
ColorNamerRuby.get_all_colours
|
132
|
+
=> [
|
133
|
+
=> { name: 'black', hex: '#000000', collection: 'basic' },
|
134
|
+
=> { name: 'blue', hex: '#0000FF', collection: 'basic' },
|
135
|
+
=> { name: 'cyan', hex: '#00FFFF', collection: 'basic' },
|
136
|
+
=> .
|
137
|
+
=> .
|
138
|
+
=> .
|
139
|
+
=> ]
|
94
140
|
```
|
95
141
|
|
96
142
|
## Options
|
@@ -98,28 +144,31 @@ ColorNamerRuby::Namer.list_names
|
|
98
144
|
### pick
|
99
145
|
|
100
146
|
This parameter allows you to filter names from the dedicated lists for faster computation.
|
101
|
-
It can be used for
|
147
|
+
It can be used for `get_name`, `get_names`, `get_all_names`, or `get_colour`, `get_colours`, `get_all_colours`.
|
102
148
|
|
103
149
|
```ruby
|
104
|
-
ColorNamerRuby
|
150
|
+
ColorNamerRuby.get_names('#3672b4', pick: ['basic', 'x11'])
|
151
|
+
=> ["steelblue", "royalblue", "cornflowerblue", "lightsteelblue", "mediumturquoise", ...]
|
105
152
|
```
|
106
153
|
|
107
154
|
### omit
|
108
155
|
|
109
156
|
The opposite of `options.pick`.
|
110
|
-
It can be used for
|
157
|
+
It can be used for `get_name`, `get_names`, `get_all_names`, or `get_colour`, `get_colours`, `get_all_colours`.
|
111
158
|
|
112
159
|
```ruby
|
113
|
-
ColorNamerRuby
|
160
|
+
ColorNamerRuby.get_names('#3672b4', omit: ['pantone', 'roygbiv', 'tailwind_v1'])
|
161
|
+
=> ["azure", "st tropaz", "steelblue", "steelblue", "steel blue", ...]
|
114
162
|
```
|
115
163
|
|
116
164
|
### limit
|
117
165
|
|
118
166
|
This option allows us to limit the number of names that are returned to keep the returned output manageable.
|
119
|
-
It can be used for `get_names` (since `get_name` already
|
167
|
+
It can be used for `get_names`, or `get_colours` (since `get_name` and `get_colour` already have a limit of 1).
|
120
168
|
|
121
169
|
```ruby
|
122
|
-
ColorNamerRuby
|
170
|
+
ColorNamerRuby.get_names('#3672b4', limit: 3)
|
171
|
+
=> ["blue-700", "azure", "blue-600"]
|
123
172
|
```
|
124
173
|
|
125
174
|
###
|
@@ -132,7 +181,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
132
181
|
|
133
182
|
## Contributing
|
134
183
|
|
135
|
-
Bug reports and pull requests are welcome on GitHub at <https://github.com/
|
184
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/louiswdavis/color_namer_ruby>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/louiswdavis/color_namer_ruby/blob/master/CODE_OF_CONDUCT.md).
|
136
185
|
|
137
186
|
## License
|
138
187
|
|
@@ -140,4 +189,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
140
189
|
|
141
190
|
## Code of Conduct
|
142
191
|
|
143
|
-
Everyone interacting in the ColorNamerRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
192
|
+
Everyone interacting in the ColorNamerRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/louiswdavis/color_namer_ruby/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
@@ -1,44 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
#
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'color_conversion'
|
4
|
+
require 'active_support/core_ext/object/blank'
|
5
|
+
require 'active_support/core_ext/string/inflections'
|
6
|
+
|
7
|
+
module ColorNamerRuby
|
8
|
+
class Distance
|
9
|
+
def self.get_names_from_hex(hex, pick, omit, limit)
|
10
|
+
@colour = ColorConversion::Color.new(hex)
|
11
|
+
|
12
|
+
colour_lists = []
|
13
|
+
|
14
|
+
ColorNamerRuby.list_collections.each do |collection_name|
|
15
|
+
next unless (pick.empty? || pick.include?(collection_name)) && !omit.include?(collection_name)
|
16
|
+
|
17
|
+
colour_lists += self.get_colour_distances_in_list(Object.const_get("ColorSwatchCollection::#{collection_name.classify}").colours)
|
18
|
+
end
|
19
|
+
|
20
|
+
colour_lists = colour_lists.flatten.compact.reject(&:empty?)
|
21
|
+
|
22
|
+
limit = colour_lists.length if limit.negative?
|
23
|
+
|
24
|
+
colour_lists.sort_by { |swatch| swatch[:distance] }.take(limit)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.get_colour_distances_in_list(colour_list)
|
28
|
+
colour_list.map do |swatch|
|
29
|
+
swatch[:distance] = self.distance_between_colours(ColorConversion::Color.new(swatch.dig(:hex)))
|
30
|
+
end
|
31
|
+
|
32
|
+
colour_list
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.distance_between_colours(comparison_colour)
|
36
|
+
# https://en.wikipedia.org/wiki/Euclidean_distance#Higher_dimensions
|
37
|
+
# closest colours across the different arrays
|
38
|
+
# TODO use LAB or HCL instead of HSL
|
39
|
+
conversion_1 = @colour.hsl
|
40
|
+
conversion_2 = comparison_colour.hsl
|
41
|
+
|
42
|
+
Math.sqrt((conversion_1[:h] - conversion_2[:h])**2 + (conversion_1[:s] - conversion_2[:s])**2 + (conversion_1[:l] - conversion_2[:l])**2)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ColorNamerRuby
|
4
|
-
VERSION =
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ColorNamerRuby
|
4
|
+
VERSION = '0.1.2'
|
5
|
+
end
|
data/lib/color_namer_ruby.rb
CHANGED
@@ -1,18 +1,70 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require_relative 'color_namer_ruby/basic'
|
6
|
-
require_relative 'color_namer_ruby/html'
|
7
|
-
require_relative 'color_namer_ruby/ntc'
|
8
|
-
require_relative 'color_namer_ruby/pantone'
|
9
|
-
require_relative 'color_namer_ruby/roygbiv'
|
10
|
-
require_relative 'color_namer_ruby/x11'
|
3
|
+
require 'color_swatch_collection'
|
11
4
|
|
12
|
-
require_relative 'color_namer_ruby/
|
5
|
+
require_relative 'color_namer_ruby/version'
|
13
6
|
require_relative 'color_namer_ruby/distance'
|
14
7
|
|
15
8
|
module ColorNamerRuby
|
16
9
|
class Error < StandardError; end
|
17
|
-
|
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
|
18
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: color_namer_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.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-
|
10
|
+
date: 2025-08-30 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: activesupport
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 6.1.3
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 6.1.3
|
12
26
|
- !ruby/object:Gem::Dependency
|
13
27
|
name: color_conversion
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,19 +38,19 @@ dependencies:
|
|
24
38
|
- !ruby/object:Gem::Version
|
25
39
|
version: 0.1.2
|
26
40
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
41
|
+
name: color_swatch_collection
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
29
43
|
requirements:
|
30
|
-
- - "
|
44
|
+
- - "~>"
|
31
45
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
46
|
+
version: 0.1.1
|
33
47
|
type: :runtime
|
34
48
|
prerelease: false
|
35
49
|
version_requirements: !ruby/object:Gem::Requirement
|
36
50
|
requirements:
|
37
|
-
- - "
|
51
|
+
- - "~>"
|
38
52
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
53
|
+
version: 0.1.1
|
40
54
|
description: Provide a color in a variety of formats and get a name back based on
|
41
55
|
a range of colour options and see how closely they match your color.
|
42
56
|
email:
|
@@ -48,15 +62,8 @@ files:
|
|
48
62
|
- README.md
|
49
63
|
- Rakefile
|
50
64
|
- lib/color_namer_ruby.rb
|
51
|
-
- lib/color_namer_ruby/basic.rb
|
52
65
|
- lib/color_namer_ruby/distance.rb
|
53
|
-
- lib/color_namer_ruby/html.rb
|
54
|
-
- lib/color_namer_ruby/namer.rb
|
55
|
-
- lib/color_namer_ruby/ntc.rb
|
56
|
-
- lib/color_namer_ruby/pantone.rb
|
57
|
-
- lib/color_namer_ruby/roygbiv.rb
|
58
66
|
- lib/color_namer_ruby/version.rb
|
59
|
-
- lib/color_namer_ruby/x11.rb
|
60
67
|
homepage: https://github.com/louiswdavis/color_namer_ruby
|
61
68
|
licenses:
|
62
69
|
- MIT
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module ColorNamerRuby
|
2
|
-
class Basic
|
3
|
-
def self.get_name_from_hex(hex)
|
4
|
-
self.colours.select { |swatch| swatch[:hex] == hex.upcase }.first&.dig(:name)
|
5
|
-
end
|
6
|
-
|
7
|
-
private
|
8
|
-
|
9
|
-
def self.colours
|
10
|
-
[
|
11
|
-
{ name: 'black', hex: '#000000' },
|
12
|
-
{ name: 'blue', hex: '#0000FF' },
|
13
|
-
{ name: 'cyan', hex: '#00FFFF' },
|
14
|
-
{ name: 'green', hex: '#008000' },
|
15
|
-
{ name: 'teal', hex: '#008080' },
|
16
|
-
{ name: 'turquoise', hex: '#40E0D0' },
|
17
|
-
{ name: 'indigo', hex: '#4B0082' },
|
18
|
-
{ name: 'gray', hex: '#808080' },
|
19
|
-
{ name: 'purple', hex: '#800080' },
|
20
|
-
{ name: 'brown', hex: '#A52A2A' },
|
21
|
-
{ name: 'tan', hex: '#D2B48C' },
|
22
|
-
{ name: 'violet', hex: '#EE82EE' },
|
23
|
-
{ name: 'beige', hex: '#F5F5DC' },
|
24
|
-
{ name: 'fuchsia', hex: '#FF00FF' },
|
25
|
-
{ name: 'gold', hex: '#FFD700' },
|
26
|
-
{ name: 'magenta', hex: '#FF00FF' },
|
27
|
-
{ name: 'orange', hex: '#FFA500' },
|
28
|
-
{ name: 'pink', hex: '#FFC0CB' },
|
29
|
-
{ name: 'red', hex: '#FF0000' },
|
30
|
-
{ name: 'white', hex: '#FFFFFF' },
|
31
|
-
{ name: 'yellow', hex: '#FFFF00' },
|
32
|
-
]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|