human_colour 0.2.0 → 0.4.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 +4 -4
- data/README.md +10 -3
- data/doc/colours.png +0 -0
- data/lib/human_colour/locales.rb +12 -0
- data/lib/human_colour/version.rb +1 -1
- data/lib/human_colour.rb +12 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 35d42d47bf0db3146c6f60d76ac09cd2e077b6dbf90d32802d59b9af4b17eac5
|
|
4
|
+
data.tar.gz: 63a243961773667626d4da42d5a1c722235ae9be7ae27ac8e982af48308cd58e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8284993d26bef8beffa6bfb3ca15d12de68913b74bf39adb3c9b5ac011cf5e348a35e853cc2a61dfacb4869f76ec9745daf71600c1fc78d5478ecff2533a5255
|
|
7
|
+
data.tar.gz: d786c21653b76d156415e0e20106970995ebc2123b6a0452246042bc3630aebf7fc44670c99ec3a7b2ab8a3a5f173329ebba7da58615837adff4fe3feb2250ed
|
data/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# HumanColour
|
|
2
2
|
|
|
3
|
+
[](https://badge.fury.io/rb/human_colour)
|
|
4
|
+
|
|
3
5
|
Simple gem for taking an RGB colour string, and converting it into a human-friendly name.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
@@ -19,12 +21,17 @@ gem install human_colour
|
|
|
19
21
|
## Usage
|
|
20
22
|
|
|
21
23
|
```ruby
|
|
24
|
+
require "human_colour"
|
|
25
|
+
|
|
22
26
|
HumanColour.parse("rgb(128,64,0)")
|
|
23
|
-
#=> "
|
|
27
|
+
#=> "brown"
|
|
24
28
|
|
|
25
|
-
# Return a colour based on the provided locale
|
|
29
|
+
# Return a colour based on the provided locale (:de, :en, :es, :fr, :it, :pt)
|
|
26
30
|
HumanColour.parse("rgb(128,64,0)", locale: :es)
|
|
27
|
-
#=> "
|
|
31
|
+
#=> "marrón"
|
|
32
|
+
|
|
33
|
+
HumanColour.parse("rgb(255, 128, 255", locale: :de)
|
|
34
|
+
#=> "hell lila"
|
|
28
35
|
```
|
|
29
36
|
|
|
30
37
|

|
data/doc/colours.png
CHANGED
|
Binary file
|
data/lib/human_colour/locales.rb
CHANGED
|
@@ -10,6 +10,7 @@ module HumanColour
|
|
|
10
10
|
},
|
|
11
11
|
colour: {
|
|
12
12
|
red: "red",
|
|
13
|
+
brown: "brown",
|
|
13
14
|
orange: "orange",
|
|
14
15
|
yellow: "yellow",
|
|
15
16
|
green: "green",
|
|
@@ -18,6 +19,7 @@ module HumanColour
|
|
|
18
19
|
pink: "pink",
|
|
19
20
|
grey: "grey",
|
|
20
21
|
black: "black",
|
|
22
|
+
near_black: "near black",
|
|
21
23
|
white: "white"
|
|
22
24
|
}
|
|
23
25
|
},
|
|
@@ -29,6 +31,7 @@ module HumanColour
|
|
|
29
31
|
},
|
|
30
32
|
colour: {
|
|
31
33
|
red: "rojo",
|
|
34
|
+
brown: "marrón",
|
|
32
35
|
orange: "naranja",
|
|
33
36
|
yellow: "amarillo",
|
|
34
37
|
green: "verde",
|
|
@@ -37,6 +40,7 @@ module HumanColour
|
|
|
37
40
|
pink: "rosa",
|
|
38
41
|
grey: "gris",
|
|
39
42
|
black: "negro",
|
|
43
|
+
near_black: "casi negro",
|
|
40
44
|
white: "blanco"
|
|
41
45
|
}
|
|
42
46
|
},
|
|
@@ -48,6 +52,7 @@ module HumanColour
|
|
|
48
52
|
},
|
|
49
53
|
colour: {
|
|
50
54
|
red: "rosso",
|
|
55
|
+
brown: "marrone",
|
|
51
56
|
orange: "arancione",
|
|
52
57
|
yellow: "giallo",
|
|
53
58
|
green: "verde",
|
|
@@ -56,6 +61,7 @@ module HumanColour
|
|
|
56
61
|
pink: "rosa",
|
|
57
62
|
grey: "grigio",
|
|
58
63
|
black: "nero",
|
|
64
|
+
near_black: "quasi nero",
|
|
59
65
|
white: "bianco"
|
|
60
66
|
}
|
|
61
67
|
},
|
|
@@ -67,6 +73,7 @@ module HumanColour
|
|
|
67
73
|
},
|
|
68
74
|
colour: {
|
|
69
75
|
red: "rouge",
|
|
76
|
+
brown: "brun",
|
|
70
77
|
orange: "orange",
|
|
71
78
|
yellow: "jaune",
|
|
72
79
|
green: "vert",
|
|
@@ -75,6 +82,7 @@ module HumanColour
|
|
|
75
82
|
pink: "rose",
|
|
76
83
|
grey: "gris",
|
|
77
84
|
black: "noir",
|
|
85
|
+
near_black: "presque noir",
|
|
78
86
|
white: "blanc"
|
|
79
87
|
}
|
|
80
88
|
},
|
|
@@ -86,6 +94,7 @@ module HumanColour
|
|
|
86
94
|
},
|
|
87
95
|
colour: {
|
|
88
96
|
red: "rot",
|
|
97
|
+
brown: "braun",
|
|
89
98
|
orange: "orange",
|
|
90
99
|
yellow: "gelb",
|
|
91
100
|
green: "grün",
|
|
@@ -94,6 +103,7 @@ module HumanColour
|
|
|
94
103
|
pink: "rosa",
|
|
95
104
|
grey: "grau",
|
|
96
105
|
black: "schwarz",
|
|
106
|
+
near_black: "fast schwarz",
|
|
97
107
|
white: "weiß"
|
|
98
108
|
}
|
|
99
109
|
},
|
|
@@ -105,6 +115,7 @@ module HumanColour
|
|
|
105
115
|
},
|
|
106
116
|
colour: {
|
|
107
117
|
red: "vermelho",
|
|
118
|
+
brown: "marrom",
|
|
108
119
|
orange: "laranja",
|
|
109
120
|
yellow: "amarelo",
|
|
110
121
|
green: "verde",
|
|
@@ -113,6 +124,7 @@ module HumanColour
|
|
|
113
124
|
pink: "rosa",
|
|
114
125
|
grey: "cinza",
|
|
115
126
|
black: "preto",
|
|
127
|
+
near_black: "quase preto",
|
|
116
128
|
white: "branco"
|
|
117
129
|
}
|
|
118
130
|
}
|
data/lib/human_colour/version.rb
CHANGED
data/lib/human_colour.rb
CHANGED
|
@@ -18,12 +18,14 @@ module HumanColour
|
|
|
18
18
|
green = matches[2].to_i / 255.0
|
|
19
19
|
blue = matches[3].to_i / 255.0
|
|
20
20
|
|
|
21
|
+
return LOCALES[locale][:colour][:near_black] if [red, green, blue].all? { |v| v < 0.126 }
|
|
22
|
+
|
|
21
23
|
l = lightness(red: red, green: green, blue: blue)
|
|
22
24
|
d = delta(red: red, green: green, blue: blue)
|
|
23
25
|
s = saturation(delta: d, lightness: l)
|
|
24
26
|
h = hue(delta: d, red: red, green: green, blue: blue)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
c = colour(saturation: s, hue: h, lightness: l)
|
|
28
|
+
t = tone(lightness: l, hue: h, base: c)
|
|
27
29
|
|
|
28
30
|
localised_tone = LOCALES[locale][:tone][t]
|
|
29
31
|
localised_colour = LOCALES[locale][:colour][c]
|
|
@@ -70,9 +72,12 @@ module HumanColour
|
|
|
70
72
|
end
|
|
71
73
|
private_class_method :hue
|
|
72
74
|
|
|
73
|
-
def self.tone(lightness:, hue:)
|
|
74
|
-
return nil if (260..320).cover?(hue) && lightness
|
|
75
|
-
return
|
|
75
|
+
def self.tone(lightness:, hue:, base:)
|
|
76
|
+
return nil if (260..320).cover?(hue) && lightness.between?(0.22, 0.28)
|
|
77
|
+
return nil if base == :brown
|
|
78
|
+
|
|
79
|
+
# All other hues
|
|
80
|
+
return :dark if lightness < 0.28
|
|
76
81
|
return :light if lightness > 0.74
|
|
77
82
|
|
|
78
83
|
nil
|
|
@@ -80,8 +85,9 @@ module HumanColour
|
|
|
80
85
|
private_class_method :tone
|
|
81
86
|
|
|
82
87
|
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
|
83
|
-
def self.colour(saturation:, hue:)
|
|
88
|
+
def self.colour(saturation:, hue:, lightness:)
|
|
84
89
|
return :grey if saturation < 0.15
|
|
90
|
+
return :brown if (15..50).cover?(hue) && lightness < 0.5
|
|
85
91
|
|
|
86
92
|
case hue
|
|
87
93
|
when 0...15, 355..360 then :red
|