human_colour 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f61159dfb6700a4655b71b7b0dde3d7dff974453210cdb74281e34bab78b1782
4
- data.tar.gz: 9d65916d7129cb05ac2ead4db9d0e827fb9841ef59fecbfc681d19dffa50e472
3
+ metadata.gz: b48c9c44e725f9a50838c47d15d75fdae3ed1867530731cd7cb7a36fdd9968f7
4
+ data.tar.gz: 85940a6afd94a1ec214b75321072b10681b18529a5df0554797f53adf06f756c
5
5
  SHA512:
6
- metadata.gz: a0982688d4fc4046d24a1c50eec07f0c93439bcdf0cbd541802866b62e2b0f4635e996c2aa2c3ee3c69883b7bef45603fbb58acf9a66e8eca4a6adb21a096796
7
- data.tar.gz: fac3b685fa6b7653881e9622705b1fac443bd00ac4725534daba4aee949ff5a7306fa79453db4a5c941c229b78ee90120e3e25c5a592c17d8b7443e001547d53
6
+ metadata.gz: 5657ca4c638bc705d22cb39790b40c074da91e62fffd03a3d64ebc08e471b586f0399d752a6c98d32db920b11620c084111ee37cccb739dbac4489bba3fd1660
7
+ data.tar.gz: b69e4a4c8fa0e369cb612be81af014904caa7ea36a069273195f404dcdf81848eb4e93506c4e8374dbac682870fbeb3cc1d6eff287a0d044502c3f71df63a004
data/.rubocop.yml CHANGED
@@ -28,6 +28,12 @@ Layout/LineContinuationSpacing: # new in 1.31
28
28
  Enabled: true
29
29
  Layout/LineEndStringConcatenationIndentation: # new in 1.18
30
30
  Enabled: true
31
+ Layout/LineLength:
32
+ Exclude:
33
+ - "spec/**/*.rb"
34
+ Layout/HashAlignment:
35
+ Exclude:
36
+ - "spec/**/*.rb"
31
37
  Layout/SpaceBeforeBrackets: # new in 1.7
32
38
  Enabled: true
33
39
  Lint/AmbiguousAssignment: # new in 1.7
@@ -293,5 +299,7 @@ Style/SuperWithArgsParentheses: # new in 1.58
293
299
  Enabled: true
294
300
  Style/SwapValues: # new in 1.1
295
301
  Enabled: true
302
+ Style/SymbolArray:
303
+ Enabled: false
296
304
  Style/YAMLFileRead: # new in 1.53
297
305
  Enabled: true
data/README.md CHANGED
@@ -20,7 +20,11 @@ gem install human_colour
20
20
 
21
21
  ```ruby
22
22
  HumanColour.parse("rgb(128,64,0)")
23
- #> "dark orange"
23
+ #=> "dark orange"
24
+
25
+ # Return a colour based on the provided locale
26
+ HumanColour.parse("rgb(128,64,0)", locale: :es)
27
+ #=> "naranja oscuro"
24
28
  ```
25
29
 
26
30
  ![alt text](https://github.com/mconnell/human_colour/blob/main/doc/colours.png?raw=true)
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Metrics/ModuleLength
4
+ module HumanColour
5
+ LOCALES = {
6
+ en: {
7
+ tone: {
8
+ light: "light",
9
+ dark: "dark"
10
+ },
11
+ colour: {
12
+ red: "red",
13
+ orange: "orange",
14
+ yellow: "yellow",
15
+ green: "green",
16
+ blue: "blue",
17
+ purple: "purple",
18
+ pink: "pink",
19
+ grey: "grey",
20
+ black: "black",
21
+ white: "white"
22
+ }
23
+ },
24
+
25
+ es: {
26
+ tone: {
27
+ light: "claro",
28
+ dark: "oscuro"
29
+ },
30
+ colour: {
31
+ red: "rojo",
32
+ orange: "naranja",
33
+ yellow: "amarillo",
34
+ green: "verde",
35
+ blue: "azul",
36
+ purple: "morado",
37
+ pink: "rosa",
38
+ grey: "gris",
39
+ black: "negro",
40
+ white: "blanco"
41
+ }
42
+ },
43
+
44
+ it: {
45
+ tone: {
46
+ light: "chiaro",
47
+ dark: "scuro"
48
+ },
49
+ colour: {
50
+ red: "rosso",
51
+ orange: "arancione",
52
+ yellow: "giallo",
53
+ green: "verde",
54
+ blue: "blu",
55
+ purple: "viola",
56
+ pink: "rosa",
57
+ grey: "grigio",
58
+ black: "nero",
59
+ white: "bianco"
60
+ }
61
+ },
62
+
63
+ fr: {
64
+ tone: {
65
+ light: "clair",
66
+ dark: "foncé"
67
+ },
68
+ colour: {
69
+ red: "rouge",
70
+ orange: "orange",
71
+ yellow: "jaune",
72
+ green: "vert",
73
+ blue: "bleu",
74
+ purple: "violet",
75
+ pink: "rose",
76
+ grey: "gris",
77
+ black: "noir",
78
+ white: "blanc"
79
+ }
80
+ },
81
+
82
+ de: {
83
+ tone: {
84
+ light: "hell",
85
+ dark: "dunkel"
86
+ },
87
+ colour: {
88
+ red: "rot",
89
+ orange: "orange",
90
+ yellow: "gelb",
91
+ green: "grün",
92
+ blue: "blau",
93
+ purple: "lila",
94
+ pink: "rosa",
95
+ grey: "grau",
96
+ black: "schwarz",
97
+ white: "weiß"
98
+ }
99
+ },
100
+
101
+ pt: {
102
+ tone: {
103
+ light: "claro",
104
+ dark: "escuro"
105
+ },
106
+ colour: {
107
+ red: "vermelho",
108
+ orange: "laranja",
109
+ yellow: "amarelo",
110
+ green: "verde",
111
+ blue: "azul",
112
+ purple: "roxo",
113
+ pink: "rosa",
114
+ grey: "cinza",
115
+ black: "preto",
116
+ white: "branco"
117
+ }
118
+ }
119
+ }.freeze
120
+ end
121
+ # rubocop:enable Metrics/ModuleLength
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HumanColour
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/human_colour.rb CHANGED
@@ -1,15 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "human_colour/version"
4
+ require_relative "human_colour/locales"
4
5
 
5
6
  module HumanColour
6
7
  class Error < StandardError; end
7
8
 
8
9
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
9
- def self.parse(rgb_string)
10
+ def self.parse(rgb_string, locale: :en)
10
11
  matches = rgb_string.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/i)
11
12
  raise Error if matches.nil?
12
13
 
14
+ return LOCALES[locale][:colour][:white] if rgb_string == "rgb(255,255,255)"
15
+ return LOCALES[locale][:colour][:black] if rgb_string == "rgb(0,0,0)"
16
+
13
17
  red = matches[1].to_i / 255.0
14
18
  green = matches[2].to_i / 255.0
15
19
  blue = matches[3].to_i / 255.0
@@ -21,13 +25,14 @@ module HumanColour
21
25
  t = tone(lightness: l, hue: h)
22
26
  c = colour(saturation: s, hue: h)
23
27
 
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)"
28
+ localised_tone = LOCALES[locale][:tone][t]
29
+ localised_colour = LOCALES[locale][:colour][c]
29
30
 
30
- name
31
+ if [:en, :de].include?(locale)
32
+ [localised_tone, localised_colour].compact.join(" ")
33
+ else
34
+ [localised_colour, localised_tone].compact.join(" ")
35
+ end
31
36
  end
32
37
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
33
38
 
@@ -67,8 +72,8 @@ module HumanColour
67
72
 
68
73
  def self.tone(lightness:, hue:)
69
74
  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
75
+ return :dark if lightness < 0.28
76
+ return :light if lightness > 0.74
72
77
 
73
78
  nil
74
79
  end
@@ -76,17 +81,17 @@ module HumanColour
76
81
 
77
82
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
78
83
  def self.colour(saturation:, hue:)
79
- return "grey" if saturation < 0.15
84
+ return :grey if saturation < 0.15
80
85
 
81
86
  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"
87
+ when 0...15, 355..360 then :red
88
+ when 15...45 then :orange
89
+ when 45...70 then :yellow
90
+ when 70...170 then :green
91
+ when 170...250 then :blue
92
+ when 250...320 then :purple
93
+ when 320...355 then :pink
94
+ else :grey
90
95
  end
91
96
  end
92
97
  # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: human_colour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Connell
@@ -22,6 +22,7 @@ files:
22
22
  - Rakefile
23
23
  - doc/colours.png
24
24
  - lib/human_colour.rb
25
+ - lib/human_colour/locales.rb
25
26
  - lib/human_colour/version.rb
26
27
  - sig/human_colour.rbs
27
28
  homepage: https://github.com/mconnell/human_colour