human_colour 0.1.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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +297 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +12 -0
- data/doc/colours.png +0 -0
- data/lib/human_colour/version.rb +5 -0
- data/lib/human_colour.rb +94 -0
- data/sig/human_colour.rbs +4 -0
- metadata +51 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f61159dfb6700a4655b71b7b0dde3d7dff974453210cdb74281e34bab78b1782
|
|
4
|
+
data.tar.gz: 9d65916d7129cb05ac2ead4db9d0e827fb9841ef59fecbfc681d19dffa50e472
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a0982688d4fc4046d24a1c50eec07f0c93439bcdf0cbd541802866b62e2b0f4635e996c2aa2c3ee3c69883b7bef45603fbb58acf9a66e8eca4a6adb21a096796
|
|
7
|
+
data.tar.gz: fac3b685fa6b7653881e9622705b1fac443bd00ac4725534daba4aee949ff5a7306fa79453db4a5c941c229b78ee90120e3e25c5a592c17d8b7443e001547d53
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 3.1
|
|
3
|
+
SuggestExtensions: false
|
|
4
|
+
|
|
5
|
+
Style/StringLiterals:
|
|
6
|
+
EnforcedStyle: double_quotes
|
|
7
|
+
|
|
8
|
+
Style/StringLiteralsInInterpolation:
|
|
9
|
+
EnforcedStyle: double_quotes
|
|
10
|
+
|
|
11
|
+
Style/Documentation:
|
|
12
|
+
Enabled: false
|
|
13
|
+
Gemspec/AddRuntimeDependency: # new in 1.65
|
|
14
|
+
Enabled: true
|
|
15
|
+
Gemspec/AttributeAssignment: # new in 1.77
|
|
16
|
+
Enabled: true
|
|
17
|
+
Gemspec/DeprecatedAttributeAssignment: # new in 1.30
|
|
18
|
+
Enabled: true
|
|
19
|
+
Gemspec/DevelopmentDependencies: # new in 1.44
|
|
20
|
+
Enabled: true
|
|
21
|
+
Gemspec/RequireMFA: # new in 1.23
|
|
22
|
+
Enabled: true
|
|
23
|
+
Layout/EmptyLinesAfterModuleInclusion: # new in 1.79
|
|
24
|
+
Enabled: true
|
|
25
|
+
Layout/LineContinuationLeadingSpace: # new in 1.31
|
|
26
|
+
Enabled: true
|
|
27
|
+
Layout/LineContinuationSpacing: # new in 1.31
|
|
28
|
+
Enabled: true
|
|
29
|
+
Layout/LineEndStringConcatenationIndentation: # new in 1.18
|
|
30
|
+
Enabled: true
|
|
31
|
+
Layout/SpaceBeforeBrackets: # new in 1.7
|
|
32
|
+
Enabled: true
|
|
33
|
+
Lint/AmbiguousAssignment: # new in 1.7
|
|
34
|
+
Enabled: true
|
|
35
|
+
Lint/AmbiguousOperatorPrecedence: # new in 1.21
|
|
36
|
+
Enabled: true
|
|
37
|
+
Lint/AmbiguousRange: # new in 1.19
|
|
38
|
+
Enabled: true
|
|
39
|
+
Lint/ArrayLiteralInRegexp: # new in 1.71
|
|
40
|
+
Enabled: true
|
|
41
|
+
Lint/ConstantOverwrittenInRescue: # new in 1.31
|
|
42
|
+
Enabled: true
|
|
43
|
+
Lint/ConstantReassignment: # new in 1.70
|
|
44
|
+
Enabled: true
|
|
45
|
+
Lint/CopDirectiveSyntax: # new in 1.72
|
|
46
|
+
Enabled: true
|
|
47
|
+
Lint/DeprecatedConstants: # new in 1.8
|
|
48
|
+
Enabled: true
|
|
49
|
+
Lint/DuplicateBranch: # new in 1.3
|
|
50
|
+
Enabled: true
|
|
51
|
+
Lint/DuplicateMagicComment: # new in 1.37
|
|
52
|
+
Enabled: true
|
|
53
|
+
Lint/DuplicateMatchPattern: # new in 1.50
|
|
54
|
+
Enabled: true
|
|
55
|
+
Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
|
|
56
|
+
Enabled: true
|
|
57
|
+
Lint/DuplicateSetElement: # new in 1.67
|
|
58
|
+
Enabled: true
|
|
59
|
+
Lint/EmptyBlock: # new in 1.1
|
|
60
|
+
Enabled: true
|
|
61
|
+
Lint/EmptyClass: # new in 1.3
|
|
62
|
+
Enabled: true
|
|
63
|
+
Lint/EmptyInPattern: # new in 1.16
|
|
64
|
+
Enabled: true
|
|
65
|
+
Lint/HashNewWithKeywordArgumentsAsDefault: # new in 1.69
|
|
66
|
+
Enabled: true
|
|
67
|
+
Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
|
|
68
|
+
Enabled: true
|
|
69
|
+
Lint/ItWithoutArgumentsInBlock: # new in 1.59
|
|
70
|
+
Enabled: true
|
|
71
|
+
Lint/LambdaWithoutLiteralBlock: # new in 1.8
|
|
72
|
+
Enabled: true
|
|
73
|
+
Lint/LiteralAssignmentInCondition: # new in 1.58
|
|
74
|
+
Enabled: true
|
|
75
|
+
Lint/MixedCaseRange: # new in 1.53
|
|
76
|
+
Enabled: true
|
|
77
|
+
Lint/NoReturnInBeginEndBlocks: # new in 1.2
|
|
78
|
+
Enabled: true
|
|
79
|
+
Lint/NonAtomicFileOperation: # new in 1.31
|
|
80
|
+
Enabled: true
|
|
81
|
+
Lint/NumberedParameterAssignment: # new in 1.9
|
|
82
|
+
Enabled: true
|
|
83
|
+
Lint/NumericOperationWithConstantResult: # new in 1.69
|
|
84
|
+
Enabled: true
|
|
85
|
+
Lint/OrAssignmentToConstant: # new in 1.9
|
|
86
|
+
Enabled: true
|
|
87
|
+
Lint/RedundantDirGlobSort: # new in 1.8
|
|
88
|
+
Enabled: true
|
|
89
|
+
Lint/RedundantRegexpQuantifiers: # new in 1.53
|
|
90
|
+
Enabled: true
|
|
91
|
+
Lint/RedundantTypeConversion: # new in 1.72
|
|
92
|
+
Enabled: true
|
|
93
|
+
Lint/RefinementImportMethods: # new in 1.27
|
|
94
|
+
Enabled: true
|
|
95
|
+
Lint/RequireRangeParentheses: # new in 1.32
|
|
96
|
+
Enabled: true
|
|
97
|
+
Lint/RequireRelativeSelfPath: # new in 1.22
|
|
98
|
+
Enabled: true
|
|
99
|
+
Lint/SharedMutableDefault: # new in 1.70
|
|
100
|
+
Enabled: true
|
|
101
|
+
Lint/SuppressedExceptionInNumberConversion: # new in 1.72
|
|
102
|
+
Enabled: true
|
|
103
|
+
Lint/SymbolConversion: # new in 1.9
|
|
104
|
+
Enabled: true
|
|
105
|
+
Lint/ToEnumArguments: # new in 1.1
|
|
106
|
+
Enabled: true
|
|
107
|
+
Lint/TripleQuotes: # new in 1.9
|
|
108
|
+
Enabled: true
|
|
109
|
+
Lint/UnescapedBracketInRegexp: # new in 1.68
|
|
110
|
+
Enabled: true
|
|
111
|
+
Lint/UnexpectedBlockArity: # new in 1.5
|
|
112
|
+
Enabled: true
|
|
113
|
+
Lint/UnmodifiedReduceAccumulator: # new in 1.1
|
|
114
|
+
Enabled: true
|
|
115
|
+
Lint/UselessConstantScoping: # new in 1.72
|
|
116
|
+
Enabled: true
|
|
117
|
+
Lint/UselessDefaultValueArgument: # new in 1.76
|
|
118
|
+
Enabled: true
|
|
119
|
+
Lint/UselessDefined: # new in 1.69
|
|
120
|
+
Enabled: true
|
|
121
|
+
Lint/UselessNumericOperation: # new in 1.66
|
|
122
|
+
Enabled: true
|
|
123
|
+
Lint/UselessOr: # new in 1.76
|
|
124
|
+
Enabled: true
|
|
125
|
+
Lint/UselessRescue: # new in 1.43
|
|
126
|
+
Enabled: true
|
|
127
|
+
Lint/UselessRuby2Keywords: # new in 1.23
|
|
128
|
+
Enabled: true
|
|
129
|
+
Metrics/CollectionLiteralLength: # new in 1.47
|
|
130
|
+
Enabled: true
|
|
131
|
+
Metrics/BlockLength:
|
|
132
|
+
Exclude:
|
|
133
|
+
- 'spec/**/*.rb'
|
|
134
|
+
Naming/BlockForwarding: # new in 1.24
|
|
135
|
+
Enabled: true
|
|
136
|
+
Naming/PredicateMethod: # new in 1.76
|
|
137
|
+
Enabled: true
|
|
138
|
+
Security/CompoundHash: # new in 1.28
|
|
139
|
+
Enabled: true
|
|
140
|
+
Security/IoMethods: # new in 1.22
|
|
141
|
+
Enabled: true
|
|
142
|
+
Style/AmbiguousEndlessMethodDefinition: # new in 1.68
|
|
143
|
+
Enabled: true
|
|
144
|
+
Style/ArgumentsForwarding: # new in 1.1
|
|
145
|
+
Enabled: true
|
|
146
|
+
Style/ArrayIntersect: # new in 1.40
|
|
147
|
+
Enabled: true
|
|
148
|
+
Style/ArrayIntersectWithSingleElement: # new in 1.81
|
|
149
|
+
Enabled: true
|
|
150
|
+
Style/BitwisePredicate: # new in 1.68
|
|
151
|
+
Enabled: true
|
|
152
|
+
Style/CollectionCompact: # new in 1.2
|
|
153
|
+
Enabled: true
|
|
154
|
+
Style/CollectionQuerying: # new in 1.77
|
|
155
|
+
Enabled: true
|
|
156
|
+
Style/CombinableDefined: # new in 1.68
|
|
157
|
+
Enabled: true
|
|
158
|
+
Style/ComparableBetween: # new in 1.74
|
|
159
|
+
Enabled: true
|
|
160
|
+
Style/ComparableClamp: # new in 1.44
|
|
161
|
+
Enabled: true
|
|
162
|
+
Style/ConcatArrayLiterals: # new in 1.41
|
|
163
|
+
Enabled: true
|
|
164
|
+
Style/DataInheritance: # new in 1.49
|
|
165
|
+
Enabled: true
|
|
166
|
+
Style/DigChain: # new in 1.69
|
|
167
|
+
Enabled: true
|
|
168
|
+
Style/DirEmpty: # new in 1.48
|
|
169
|
+
Enabled: true
|
|
170
|
+
Style/DocumentDynamicEvalDefinition: # new in 1.1
|
|
171
|
+
Enabled: true
|
|
172
|
+
Style/EmptyHeredoc: # new in 1.32
|
|
173
|
+
Enabled: true
|
|
174
|
+
Style/EmptyStringInsideInterpolation: # new in 1.76
|
|
175
|
+
Enabled: true
|
|
176
|
+
Style/EndlessMethod: # new in 1.8
|
|
177
|
+
Enabled: true
|
|
178
|
+
Style/EnvHome: # new in 1.29
|
|
179
|
+
Enabled: true
|
|
180
|
+
Style/ExactRegexpMatch: # new in 1.51
|
|
181
|
+
Enabled: true
|
|
182
|
+
Style/FetchEnvVar: # new in 1.28
|
|
183
|
+
Enabled: true
|
|
184
|
+
Style/FileEmpty: # new in 1.48
|
|
185
|
+
Enabled: true
|
|
186
|
+
Style/FileNull: # new in 1.69
|
|
187
|
+
Enabled: true
|
|
188
|
+
Style/FileRead: # new in 1.24
|
|
189
|
+
Enabled: true
|
|
190
|
+
Style/FileTouch: # new in 1.69
|
|
191
|
+
Enabled: true
|
|
192
|
+
Style/FileWrite: # new in 1.24
|
|
193
|
+
Enabled: true
|
|
194
|
+
Style/HashConversion: # new in 1.10
|
|
195
|
+
Enabled: true
|
|
196
|
+
Style/HashExcept: # new in 1.7
|
|
197
|
+
Enabled: true
|
|
198
|
+
Style/HashFetchChain: # new in 1.75
|
|
199
|
+
Enabled: true
|
|
200
|
+
Style/HashSlice: # new in 1.71
|
|
201
|
+
Enabled: true
|
|
202
|
+
Style/IfWithBooleanLiteralBranches: # new in 1.9
|
|
203
|
+
Enabled: true
|
|
204
|
+
Style/InPatternThen: # new in 1.16
|
|
205
|
+
Enabled: true
|
|
206
|
+
Style/ItAssignment: # new in 1.70
|
|
207
|
+
Enabled: true
|
|
208
|
+
Style/ItBlockParameter: # new in 1.75
|
|
209
|
+
Enabled: true
|
|
210
|
+
Style/KeywordArgumentsMerging: # new in 1.68
|
|
211
|
+
Enabled: true
|
|
212
|
+
Style/MagicCommentFormat: # new in 1.35
|
|
213
|
+
Enabled: true
|
|
214
|
+
Style/MapCompactWithConditionalBlock: # new in 1.30
|
|
215
|
+
Enabled: true
|
|
216
|
+
Style/MapIntoArray: # new in 1.63
|
|
217
|
+
Enabled: true
|
|
218
|
+
Style/MapToHash: # new in 1.24
|
|
219
|
+
Enabled: true
|
|
220
|
+
Style/MapToSet: # new in 1.42
|
|
221
|
+
Enabled: true
|
|
222
|
+
Style/MinMaxComparison: # new in 1.42
|
|
223
|
+
Enabled: true
|
|
224
|
+
Style/MultilineInPatternThen: # new in 1.16
|
|
225
|
+
Enabled: true
|
|
226
|
+
Style/NegatedIfElseCondition: # new in 1.2
|
|
227
|
+
Enabled: true
|
|
228
|
+
Style/NestedFileDirname: # new in 1.26
|
|
229
|
+
Enabled: true
|
|
230
|
+
Style/NilLambda: # new in 1.3
|
|
231
|
+
Enabled: true
|
|
232
|
+
Style/NumberedParameters: # new in 1.22
|
|
233
|
+
Enabled: true
|
|
234
|
+
Style/NumberedParametersLimit: # new in 1.22
|
|
235
|
+
Enabled: true
|
|
236
|
+
Style/ObjectThen: # new in 1.28
|
|
237
|
+
Enabled: true
|
|
238
|
+
Style/OpenStructUse: # new in 1.23
|
|
239
|
+
Enabled: true
|
|
240
|
+
Style/OperatorMethodCall: # new in 1.37
|
|
241
|
+
Enabled: true
|
|
242
|
+
Style/QuotedSymbols: # new in 1.16
|
|
243
|
+
Enabled: true
|
|
244
|
+
Style/RedundantArgument: # new in 1.4
|
|
245
|
+
Enabled: true
|
|
246
|
+
Style/RedundantArrayConstructor: # new in 1.52
|
|
247
|
+
Enabled: true
|
|
248
|
+
Style/RedundantArrayFlatten: # new in 1.76
|
|
249
|
+
Enabled: true
|
|
250
|
+
Style/RedundantConstantBase: # new in 1.40
|
|
251
|
+
Enabled: true
|
|
252
|
+
Style/RedundantCurrentDirectoryInPath: # new in 1.53
|
|
253
|
+
Enabled: true
|
|
254
|
+
Style/RedundantDoubleSplatHashBraces: # new in 1.41
|
|
255
|
+
Enabled: true
|
|
256
|
+
Style/RedundantEach: # new in 1.38
|
|
257
|
+
Enabled: true
|
|
258
|
+
Style/RedundantFilterChain: # new in 1.52
|
|
259
|
+
Enabled: true
|
|
260
|
+
Style/RedundantFormat: # new in 1.72
|
|
261
|
+
Enabled: true
|
|
262
|
+
Style/RedundantHeredocDelimiterQuotes: # new in 1.45
|
|
263
|
+
Enabled: true
|
|
264
|
+
Style/RedundantInitialize: # new in 1.27
|
|
265
|
+
Enabled: true
|
|
266
|
+
Style/RedundantInterpolationUnfreeze: # new in 1.66
|
|
267
|
+
Enabled: true
|
|
268
|
+
Style/RedundantLineContinuation: # new in 1.49
|
|
269
|
+
Enabled: true
|
|
270
|
+
Style/RedundantRegexpArgument: # new in 1.53
|
|
271
|
+
Enabled: true
|
|
272
|
+
Style/RedundantRegexpConstructor: # new in 1.52
|
|
273
|
+
Enabled: true
|
|
274
|
+
Style/RedundantSelfAssignmentBranch: # new in 1.19
|
|
275
|
+
Enabled: true
|
|
276
|
+
Style/RedundantStringEscape: # new in 1.37
|
|
277
|
+
Enabled: true
|
|
278
|
+
Style/ReturnNilInPredicateMethodDefinition: # new in 1.53
|
|
279
|
+
Enabled: true
|
|
280
|
+
Style/SafeNavigationChainLength: # new in 1.68
|
|
281
|
+
Enabled: true
|
|
282
|
+
Style/SelectByRegexp: # new in 1.22
|
|
283
|
+
Enabled: true
|
|
284
|
+
Style/SendWithLiteralMethodName: # new in 1.64
|
|
285
|
+
Enabled: true
|
|
286
|
+
Style/SingleLineDoEndBlock: # new in 1.57
|
|
287
|
+
Enabled: true
|
|
288
|
+
Style/StringChars: # new in 1.12
|
|
289
|
+
Enabled: true
|
|
290
|
+
Style/SuperArguments: # new in 1.64
|
|
291
|
+
Enabled: true
|
|
292
|
+
Style/SuperWithArgsParentheses: # new in 1.58
|
|
293
|
+
Enabled: true
|
|
294
|
+
Style/SwapValues: # new in 1.1
|
|
295
|
+
Enabled: true
|
|
296
|
+
Style/YAMLFileRead: # new in 1.53
|
|
297
|
+
Enabled: true
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mark Connell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# HumanColour
|
|
2
|
+
|
|
3
|
+
Simple gem for taking an RGB colour string, and converting it into a human-friendly name.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bundle add human_colour
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
gem install human_colour
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
HumanColour.parse("rgb(128,64,0)")
|
|
23
|
+
#> "dark orange"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+
|
|
28
|
+
## Development
|
|
29
|
+
|
|
30
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
31
|
+
|
|
32
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/doc/colours.png
ADDED
|
Binary file
|
data/lib/human_colour.rb
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "human_colour/version"
|
|
4
|
+
|
|
5
|
+
module HumanColour
|
|
6
|
+
class Error < StandardError; end
|
|
7
|
+
|
|
8
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
9
|
+
def self.parse(rgb_string)
|
|
10
|
+
matches = rgb_string.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/i)
|
|
11
|
+
raise Error if matches.nil?
|
|
12
|
+
|
|
13
|
+
red = matches[1].to_i / 255.0
|
|
14
|
+
green = matches[2].to_i / 255.0
|
|
15
|
+
blue = matches[3].to_i / 255.0
|
|
16
|
+
|
|
17
|
+
l = lightness(red: red, green: green, blue: blue)
|
|
18
|
+
d = delta(red: red, green: green, blue: blue)
|
|
19
|
+
s = saturation(delta: d, lightness: l)
|
|
20
|
+
h = hue(delta: d, red: red, green: green, blue: blue)
|
|
21
|
+
t = tone(lightness: l, hue: h)
|
|
22
|
+
c = colour(saturation: s, hue: h)
|
|
23
|
+
|
|
24
|
+
name = [t, c].compact.join(" ")
|
|
25
|
+
|
|
26
|
+
# alias extremes for nicer names
|
|
27
|
+
return "white" if rgb_string == "rgb(255,255,255)"
|
|
28
|
+
return "black" if rgb_string == "rgb(0,0,0)"
|
|
29
|
+
|
|
30
|
+
name
|
|
31
|
+
end
|
|
32
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
33
|
+
|
|
34
|
+
def self.delta(red:, green:, blue:)
|
|
35
|
+
[red, green, blue].max - [red, green, blue].min
|
|
36
|
+
end
|
|
37
|
+
private_class_method :delta
|
|
38
|
+
|
|
39
|
+
def self.lightness(red:, green:, blue:)
|
|
40
|
+
([red, green, blue].max + [red, green, blue].min) / 2
|
|
41
|
+
end
|
|
42
|
+
private_class_method :lightness
|
|
43
|
+
|
|
44
|
+
def self.saturation(delta:, lightness:)
|
|
45
|
+
if delta.zero?
|
|
46
|
+
0
|
|
47
|
+
else
|
|
48
|
+
delta / (1 - ((2 * lightness) - 1).abs)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
private_class_method :saturation
|
|
52
|
+
|
|
53
|
+
def self.hue(delta:, red:, green:, blue:)
|
|
54
|
+
return 0 if delta.zero?
|
|
55
|
+
|
|
56
|
+
max = [red, green, blue].max
|
|
57
|
+
h = if max == red
|
|
58
|
+
((green - blue) / delta) % 6
|
|
59
|
+
elsif max == green
|
|
60
|
+
((blue - red) / delta) + 2
|
|
61
|
+
else
|
|
62
|
+
((red - green) / delta) + 4
|
|
63
|
+
end
|
|
64
|
+
h * 60
|
|
65
|
+
end
|
|
66
|
+
private_class_method :hue
|
|
67
|
+
|
|
68
|
+
def self.tone(lightness:, hue:)
|
|
69
|
+
return nil if (260..320).cover?(hue) && lightness >= 0.22 && lightness < 0.28
|
|
70
|
+
return "dark" if lightness < 0.28
|
|
71
|
+
return "light" if lightness > 0.74
|
|
72
|
+
|
|
73
|
+
nil
|
|
74
|
+
end
|
|
75
|
+
private_class_method :tone
|
|
76
|
+
|
|
77
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
|
78
|
+
def self.colour(saturation:, hue:)
|
|
79
|
+
return "grey" if saturation < 0.15
|
|
80
|
+
|
|
81
|
+
case hue
|
|
82
|
+
when 0...15, 355..360 then "red"
|
|
83
|
+
when 15...45 then "orange"
|
|
84
|
+
when 45...70 then "yellow"
|
|
85
|
+
when 70...170 then "green"
|
|
86
|
+
when 170...250 then "blue"
|
|
87
|
+
when 250...320 then "purple"
|
|
88
|
+
when 320...355 then "pink"
|
|
89
|
+
else "grey"
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
|
93
|
+
private_class_method :colour
|
|
94
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: human_colour
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Mark Connell
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
email:
|
|
13
|
+
- mark@connell.uk
|
|
14
|
+
executables: []
|
|
15
|
+
extensions: []
|
|
16
|
+
extra_rdoc_files: []
|
|
17
|
+
files:
|
|
18
|
+
- ".rspec"
|
|
19
|
+
- ".rubocop.yml"
|
|
20
|
+
- LICENSE.txt
|
|
21
|
+
- README.md
|
|
22
|
+
- Rakefile
|
|
23
|
+
- doc/colours.png
|
|
24
|
+
- lib/human_colour.rb
|
|
25
|
+
- lib/human_colour/version.rb
|
|
26
|
+
- sig/human_colour.rbs
|
|
27
|
+
homepage: https://github.com/mconnell/human_colour
|
|
28
|
+
licenses:
|
|
29
|
+
- MIT
|
|
30
|
+
metadata:
|
|
31
|
+
homepage_uri: https://github.com/mconnell/human_colour
|
|
32
|
+
source_code_uri: https://github.com/mconnell/human_colour
|
|
33
|
+
rubygems_mfa_required: 'true'
|
|
34
|
+
rdoc_options: []
|
|
35
|
+
require_paths:
|
|
36
|
+
- lib
|
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: 3.1.0
|
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
requirements: []
|
|
48
|
+
rubygems_version: 3.6.7
|
|
49
|
+
specification_version: 4
|
|
50
|
+
summary: Small library to help convert a computer-friendly colour into something human-friendly
|
|
51
|
+
test_files: []
|