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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b48c9c44e725f9a50838c47d15d75fdae3ed1867530731cd7cb7a36fdd9968f7
4
- data.tar.gz: 85940a6afd94a1ec214b75321072b10681b18529a5df0554797f53adf06f756c
3
+ metadata.gz: 35d42d47bf0db3146c6f60d76ac09cd2e077b6dbf90d32802d59b9af4b17eac5
4
+ data.tar.gz: 63a243961773667626d4da42d5a1c722235ae9be7ae27ac8e982af48308cd58e
5
5
  SHA512:
6
- metadata.gz: 5657ca4c638bc705d22cb39790b40c074da91e62fffd03a3d64ebc08e471b586f0399d752a6c98d32db920b11620c084111ee37cccb739dbac4489bba3fd1660
7
- data.tar.gz: b69e4a4c8fa0e369cb612be81af014904caa7ea36a069273195f404dcdf81848eb4e93506c4e8374dbac682870fbeb3cc1d6eff287a0d044502c3f71df63a004
6
+ metadata.gz: 8284993d26bef8beffa6bfb3ca15d12de68913b74bf39adb3c9b5ac011cf5e348a35e853cc2a61dfacb4869f76ec9745daf71600c1fc78d5478ecff2533a5255
7
+ data.tar.gz: d786c21653b76d156415e0e20106970995ebc2123b6a0452246042bc3630aebf7fc44670c99ec3a7b2ab8a3a5f173329ebba7da58615837adff4fe3feb2250ed
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # HumanColour
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/human_colour.svg?icon=si%3Arubygems&icon_color=%23ffffff)](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
- #=> "dark orange"
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
- #=> "naranja oscuro"
31
+ #=> "marrón"
32
+
33
+ HumanColour.parse("rgb(255, 128, 255", locale: :de)
34
+ #=> "hell lila"
28
35
  ```
29
36
 
30
37
  ![alt text](https://github.com/mconnell/human_colour/blob/main/doc/colours.png?raw=true)
data/doc/colours.png CHANGED
Binary file
@@ -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
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HumanColour
4
- VERSION = "0.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
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
- t = tone(lightness: l, hue: h)
26
- c = colour(saturation: s, hue: h)
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 >= 0.22 && lightness < 0.28
75
- return :dark if lightness < 0.28
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
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.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Connell