human_colour 0.3.0 → 0.5.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 +7 -2
- data/lib/human_colour/locales.rb +27 -0
- data/lib/human_colour/version.rb +1 -1
- data/lib/human_colour.rb +6 -2
- 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: 65e374f2dc19de0b62fb2736df8235840d63b857d37d96a60b19f2c5ed116c9c
|
|
4
|
+
data.tar.gz: 6e1cf68e77af801169bcee3d27cb69970c2e5c6c71c944e714957840ec04f922
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7c7b9f913e5ee8cd0a84a835d5ee9f84016945a1efd8dfa2e10374f49790338c26a6e29dca2d5174488353e834b6f7882eb977c68e44e0f46e03fe7445f148b9
|
|
7
|
+
data.tar.gz: 10ec2faec4a21061765d881b69380acf7ca1c935ef2f55f73199da5d9d4169cb8729c5adc5bd3a4cbc1f67a55fde4d02e1c1602aa2c170007b22ed3e9631c2a0
|
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
|
|
@@ -22,11 +24,14 @@ gem install human_colour
|
|
|
22
24
|
require "human_colour"
|
|
23
25
|
|
|
24
26
|
HumanColour.parse("rgb(128,64,0)")
|
|
25
|
-
#=> "
|
|
27
|
+
#=> "brown"
|
|
28
|
+
|
|
29
|
+
HumanColour.parse("rgb(30, 20, 10)")
|
|
30
|
+
#=> "near black"
|
|
26
31
|
|
|
27
32
|
# Return a colour based on the provided locale (:de, :en, :es, :fr, :it, :pt)
|
|
28
33
|
HumanColour.parse("rgb(128,64,0)", locale: :es)
|
|
29
|
-
#=> "
|
|
34
|
+
#=> "marrón"
|
|
30
35
|
|
|
31
36
|
HumanColour.parse("rgb(255, 128, 255", locale: :de)
|
|
32
37
|
#=> "hell lila"
|
data/lib/human_colour/locales.rb
CHANGED
|
@@ -19,6 +19,7 @@ module HumanColour
|
|
|
19
19
|
pink: "pink",
|
|
20
20
|
grey: "grey",
|
|
21
21
|
black: "black",
|
|
22
|
+
near_black: "near black",
|
|
22
23
|
white: "white"
|
|
23
24
|
}
|
|
24
25
|
},
|
|
@@ -39,6 +40,7 @@ module HumanColour
|
|
|
39
40
|
pink: "rosa",
|
|
40
41
|
grey: "gris",
|
|
41
42
|
black: "negro",
|
|
43
|
+
near_black: "casi negro",
|
|
42
44
|
white: "blanco"
|
|
43
45
|
}
|
|
44
46
|
},
|
|
@@ -59,6 +61,7 @@ module HumanColour
|
|
|
59
61
|
pink: "rosa",
|
|
60
62
|
grey: "grigio",
|
|
61
63
|
black: "nero",
|
|
64
|
+
near_black: "quasi nero",
|
|
62
65
|
white: "bianco"
|
|
63
66
|
}
|
|
64
67
|
},
|
|
@@ -79,6 +82,7 @@ module HumanColour
|
|
|
79
82
|
pink: "rose",
|
|
80
83
|
grey: "gris",
|
|
81
84
|
black: "noir",
|
|
85
|
+
near_black: "presque noir",
|
|
82
86
|
white: "blanc"
|
|
83
87
|
}
|
|
84
88
|
},
|
|
@@ -99,6 +103,7 @@ module HumanColour
|
|
|
99
103
|
pink: "rosa",
|
|
100
104
|
grey: "grau",
|
|
101
105
|
black: "schwarz",
|
|
106
|
+
near_black: "fast schwarz",
|
|
102
107
|
white: "weiß"
|
|
103
108
|
}
|
|
104
109
|
},
|
|
@@ -119,8 +124,30 @@ module HumanColour
|
|
|
119
124
|
pink: "rosa",
|
|
120
125
|
grey: "cinza",
|
|
121
126
|
black: "preto",
|
|
127
|
+
near_black: "quase preto",
|
|
122
128
|
white: "branco"
|
|
123
129
|
}
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
ja: {
|
|
133
|
+
tone: {
|
|
134
|
+
light: "薄い",
|
|
135
|
+
dark: "濃い"
|
|
136
|
+
},
|
|
137
|
+
colour: {
|
|
138
|
+
red: "赤",
|
|
139
|
+
brown: "茶色",
|
|
140
|
+
orange: "オレンジ",
|
|
141
|
+
yellow: "黄色",
|
|
142
|
+
green: "緑",
|
|
143
|
+
blue: "青",
|
|
144
|
+
purple: "紫",
|
|
145
|
+
pink: "ピンク",
|
|
146
|
+
grey: "灰色",
|
|
147
|
+
black: "黒",
|
|
148
|
+
near_black: "黒に近い",
|
|
149
|
+
white: "白"
|
|
150
|
+
}
|
|
124
151
|
}
|
|
125
152
|
}.freeze
|
|
126
153
|
end
|
data/lib/human_colour/version.rb
CHANGED
data/lib/human_colour.rb
CHANGED
|
@@ -6,7 +6,7 @@ require_relative "human_colour/locales"
|
|
|
6
6
|
module HumanColour
|
|
7
7
|
class Error < StandardError; end
|
|
8
8
|
|
|
9
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
9
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
|
10
10
|
def self.parse(rgb_string, locale: :en)
|
|
11
11
|
matches = rgb_string.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/i)
|
|
12
12
|
raise Error if matches.nil?
|
|
@@ -18,6 +18,8 @@ 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)
|
|
@@ -30,11 +32,13 @@ module HumanColour
|
|
|
30
32
|
|
|
31
33
|
if [:en, :de].include?(locale)
|
|
32
34
|
[localised_tone, localised_colour].compact.join(" ")
|
|
35
|
+
elsif [:ja].include?(locale)
|
|
36
|
+
[localised_tone, localised_colour].compact.join
|
|
33
37
|
else
|
|
34
38
|
[localised_colour, localised_tone].compact.join(" ")
|
|
35
39
|
end
|
|
36
40
|
end
|
|
37
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
41
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
|
38
42
|
|
|
39
43
|
def self.delta(red:, green:, blue:)
|
|
40
44
|
[red, green, blue].max - [red, green, blue].min
|