color_hash 0.1.0 → 1.0.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: ddbbc3200aa561a17d07ecbd7c209822e97d276d35965dfc6027ac16cd3dfd4c
4
- data.tar.gz: 68bda518a95968b69339e1b30e94b45bd42e14948fec050194944b5a2ec19a0b
3
+ metadata.gz: '0492acdb34c326758582df5926c316d5610cfd5a16dc52902f550610866849cf'
4
+ data.tar.gz: 003edf282db34a6849d14baf805347d9a42dfd964ddddd56c79c06481ac46893
5
5
  SHA512:
6
- metadata.gz: 7156629804899b663856449220ecb2e159b4d75ff29dc58634c19c7628e83bcf739bbfe779a507a23e111f2472729e2d9c42cd131544af01b341254565bde553
7
- data.tar.gz: 35d4e8451d94797e33c7c9aecfc3d3e9484120ceabca55410b7fb20cd8f9705a8c83f792967f77080c29da2ce939fafd471cf16242613ff75894de4b23599656
6
+ metadata.gz: c73c3b8c22e7e5bdf5ad7847e408f4daa334cec0c8422a0f92a556ac0320e6353a3013cce7cee68816ddb241cc4864407159f3ced02839bf46d592510770de15
7
+ data.tar.gz: a28eb8a2e47f5d98a5221740f154bc768557e52738481945e6c623e4f60e18c712c7b3becbb0fcb54cc43db6b616ce9cd19395eb204fbd05dd49df9106c51169
data/.rubocop.yml CHANGED
@@ -1,13 +1,4 @@
1
- AllCops:
2
- TargetRubyVersion: 2.6
3
-
4
- Style/StringLiterals:
5
- Enabled: true
6
- EnforcedStyle: double_quotes
7
-
8
- Style/StringLiteralsInInterpolation:
9
- Enabled: true
10
- EnforcedStyle: double_quotes
11
-
12
- Layout/LineLength:
13
- Max: 120
1
+ inherit_gem: { kuyio-rubocop: rubocop-default.yml }
2
+ inherit_mode:
3
+ merge:
4
+ - Exclude
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.0.0] - 2026-07-15
4
+
5
+ - Update dependencies and bundler
6
+ - Switch to kuyio-rubocop for shared lint configuration
7
+ - Bump required Ruby version to >= 3.4.0
8
+ - Add rubygems_mfa_required metadata to gemspec
9
+ - Fix rubocop offenses (ASCII comments, ambiguous precedence, stale cop directives)
10
+ - Add Makefile with build, test, clean, and deploy targets
11
+ - Optimize Generator: resolve hash function once via Method#call instead of send
12
+ - Simplify rgb2hex using format string
13
+ - Avoid unnecessary array allocation in hash_bkdr
14
+ - Extract repeated float constants (ONE_THIRD, ONE_SIXTH, TWO_THIRDS)
15
+ - Clean up dead code and misleading float modulo
16
+
3
17
  ## [0.1.0] - 2022-12-15
4
18
 
5
19
  - Initial release
data/Gemfile CHANGED
@@ -9,4 +9,4 @@ gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
- gem "rubocop", "~> 1.21"
12
+ gem "kuyio-rubocop", github: "kuyio/kuyio-rubocop"
data/Gemfile.lock CHANGED
@@ -1,3 +1,13 @@
1
+ GIT
2
+ remote: https://github.com/kuyio/kuyio-rubocop.git
3
+ revision: f7774235c8fddd1855cda03ea0415b5dad005621
4
+ specs:
5
+ kuyio-rubocop (0.4.1)
6
+ rubocop (~> 1.85.0)
7
+ rubocop-performance (~> 1.26.0)
8
+ rubocop-rails (~> 2.34.0)
9
+ rubocop-rspec (~> 3.9.0)
10
+
1
11
  PATH
2
12
  remote: .
3
13
  specs:
@@ -6,52 +16,114 @@ PATH
6
16
  GEM
7
17
  remote: https://rubygems.org/
8
18
  specs:
9
- ast (2.4.2)
10
- diff-lcs (1.5.0)
11
- json (2.6.2)
12
- parallel (1.22.1)
13
- parser (3.1.2.1)
19
+ activesupport (8.1.3)
20
+ base64
21
+ bigdecimal
22
+ concurrent-ruby (~> 1.0, >= 1.3.1)
23
+ connection_pool (>= 2.2.5)
24
+ drb
25
+ i18n (>= 1.6, < 2)
26
+ json
27
+ logger (>= 1.4.2)
28
+ minitest (>= 5.1)
29
+ securerandom (>= 0.3)
30
+ tzinfo (~> 2.0, >= 2.0.5)
31
+ uri (>= 0.13.1)
32
+ ast (2.4.3)
33
+ base64 (0.3.0)
34
+ bigdecimal (4.1.2)
35
+ concurrent-ruby (1.3.7)
36
+ connection_pool (3.0.2)
37
+ diff-lcs (1.6.2)
38
+ drb (2.2.3)
39
+ hana (1.3.7)
40
+ i18n (1.15.2)
41
+ concurrent-ruby (~> 1.0)
42
+ json (2.21.1)
43
+ json_schemer (2.5.0)
44
+ bigdecimal
45
+ hana (~> 1.3)
46
+ regexp_parser (~> 2.0)
47
+ simpleidn (~> 0.2)
48
+ language_server-protocol (3.17.0.6)
49
+ lint_roller (1.1.0)
50
+ logger (1.7.0)
51
+ mcp (0.24.0)
52
+ json_schemer (>= 2.4)
53
+ minitest (6.0.6)
54
+ drb (~> 2.0)
55
+ prism (~> 1.5)
56
+ parallel (1.28.0)
57
+ parser (3.3.11.1)
14
58
  ast (~> 2.4.1)
59
+ racc
60
+ prism (1.9.0)
61
+ racc (1.8.1)
62
+ rack (3.2.6)
15
63
  rainbow (3.1.1)
16
- rake (13.0.6)
17
- regexp_parser (2.6.1)
18
- rexml (3.2.5)
19
- rspec (3.11.0)
20
- rspec-core (~> 3.11.0)
21
- rspec-expectations (~> 3.11.0)
22
- rspec-mocks (~> 3.11.0)
23
- rspec-core (3.11.0)
24
- rspec-support (~> 3.11.0)
25
- rspec-expectations (3.11.1)
64
+ rake (13.4.2)
65
+ regexp_parser (2.12.0)
66
+ rspec (3.13.2)
67
+ rspec-core (~> 3.13.0)
68
+ rspec-expectations (~> 3.13.0)
69
+ rspec-mocks (~> 3.13.0)
70
+ rspec-core (3.13.6)
71
+ rspec-support (~> 3.13.0)
72
+ rspec-expectations (3.13.5)
26
73
  diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.11.0)
28
- rspec-mocks (3.11.1)
74
+ rspec-support (~> 3.13.0)
75
+ rspec-mocks (3.13.8)
29
76
  diff-lcs (>= 1.2.0, < 2.0)
30
- rspec-support (~> 3.11.0)
31
- rspec-support (3.11.1)
32
- rubocop (1.36.0)
77
+ rspec-support (~> 3.13.0)
78
+ rspec-support (3.13.7)
79
+ rubocop (1.85.1)
33
80
  json (~> 2.3)
81
+ language_server-protocol (~> 3.17.0.2)
82
+ lint_roller (~> 1.1.0)
83
+ mcp (~> 0.6)
34
84
  parallel (~> 1.10)
35
- parser (>= 3.1.2.1)
85
+ parser (>= 3.3.0.2)
36
86
  rainbow (>= 2.2.2, < 4.0)
37
- regexp_parser (>= 1.8, < 3.0)
38
- rexml (>= 3.2.5, < 4.0)
39
- rubocop-ast (>= 1.20.1, < 2.0)
87
+ regexp_parser (>= 2.9.3, < 3.0)
88
+ rubocop-ast (>= 1.49.0, < 2.0)
40
89
  ruby-progressbar (~> 1.7)
41
- unicode-display_width (>= 1.4.0, < 3.0)
42
- rubocop-ast (1.21.0)
43
- parser (>= 3.1.1.0)
44
- ruby-progressbar (1.11.0)
45
- unicode-display_width (2.3.0)
90
+ unicode-display_width (>= 2.4.0, < 4.0)
91
+ rubocop-ast (1.50.0)
92
+ parser (>= 3.3.7.2)
93
+ prism (~> 1.7)
94
+ rubocop-performance (1.26.1)
95
+ lint_roller (~> 1.1)
96
+ rubocop (>= 1.75.0, < 2.0)
97
+ rubocop-ast (>= 1.47.1, < 2.0)
98
+ rubocop-rails (2.34.3)
99
+ activesupport (>= 4.2.0)
100
+ lint_roller (~> 1.1)
101
+ rack (>= 1.1)
102
+ rubocop (>= 1.75.0, < 2.0)
103
+ rubocop-ast (>= 1.44.0, < 2.0)
104
+ rubocop-rspec (3.9.0)
105
+ lint_roller (~> 1.1)
106
+ rubocop (~> 1.81)
107
+ ruby-progressbar (1.13.0)
108
+ securerandom (0.4.1)
109
+ simpleidn (0.2.3)
110
+ tzinfo (2.0.6)
111
+ concurrent-ruby (~> 1.0)
112
+ unicode-display_width (3.2.0)
113
+ unicode-emoji (~> 4.1)
114
+ unicode-emoji (4.2.0)
115
+ uri (1.1.1)
46
116
 
47
117
  PLATFORMS
48
118
  arm64-darwin-21
119
+ arm64-darwin-24
120
+ x86_64-linux
49
121
 
50
122
  DEPENDENCIES
51
123
  color_hash!
124
+ kuyio-rubocop!
52
125
  rake (~> 13.0)
53
126
  rspec (~> 3.0)
54
- rubocop (~> 1.21)
55
127
 
56
128
  BUNDLED WITH
57
- 2.3.17
129
+ 4.0.6
data/Makefile ADDED
@@ -0,0 +1,21 @@
1
+ .PHONY: build test clean deploy lint rubocop spec
2
+
3
+ build: clean
4
+ gem build color_hash.gemspec
5
+
6
+ test: lint spec
7
+
8
+ lint: rubocop
9
+
10
+ rubocop:
11
+ bundle exec rubocop
12
+
13
+ spec:
14
+ bundle exec rspec
15
+
16
+ clean:
17
+ rm -f color_hash-*.gem
18
+ rm -rf pkg
19
+
20
+ deploy: build
21
+ gem push color_hash-*.gem
@@ -36,65 +36,59 @@ module ColorHash
36
36
  @lightness = lightness
37
37
  @saturation = saturation
38
38
  @hue = hue
39
- @hash_func = hash
39
+ @hash_method = method(:"hash_#{hash}")
40
40
  end
41
41
 
42
- # Magic
43
42
  HUE_RESOLUTION = 727
43
+ ONE_THIRD = 1.0 / 3.0
44
+ ONE_SIXTH = 1.0 / 6.0
45
+ TWO_THIRDS = 2.0 / 3.0
44
46
 
45
- # rubocop:disable Metrics/AbcSize
46
47
  # Calculates an HSL color value returned as an Array of the form [H, S, L]
47
48
  # from a given string.
48
49
  #
49
- # H Hue [0, 360)
50
- # S Saturation [0, 1]
51
- # L Lightness [0, 1]
50
+ # H Hue in [0, 360)
51
+ # S Saturation in [0, 1]
52
+ # L Lightness in [0, 1]
52
53
  def hsl(str)
53
- hash = send("hash_#{@hash_func}", str)
54
+ hash = @hash_method.call(str)
54
55
 
55
56
  hr = @hue[hash % @hue.count]
56
- h = ((hash / @hue.count) % HUE_RESOLUTION) * (hr[:max] - hr[:min]) / HUE_RESOLUTION + hr[:min]
57
-
58
- # h = hash % 359
57
+ h = (((hash / @hue.count) % HUE_RESOLUTION) * (hr[:max] - hr[:min]) / HUE_RESOLUTION) + hr[:min]
59
58
 
60
59
  hash = (hash / 360.0).ceil
61
- s = @saturation[hash % @saturation.count.to_f]
60
+ s = @saturation[hash % @saturation.count]
62
61
 
63
62
  hash = (hash / @saturation.count.to_f).ceil
64
63
  l = @lightness[hash % @lightness.count]
65
64
 
66
65
  [h, s, l]
67
66
  end
68
- # rubocop:enable Metrics/AbcSize
69
67
 
70
68
  # Calculates an RGB color value returned as an Array of the form [R, G, B]
71
69
  # from a given string.
72
70
  #
73
- # R, G, B [0, 255]
71
+ # R, G, B in [0, 255]
74
72
  def rgb(str)
75
73
  hsl2rgb(*hsl(str))
76
74
  end
77
75
 
78
- # rubocop:disable Metrics/AbcSize
79
- # rubocop:disable Metrics/CyclomaticComplexity
80
- # rubocop:disable Metrics/PerceivedComplexity
81
- # rubocop:disable Metrics/MethodLength
82
76
  # Converts a color specified by its hue, saturation and lightness to an RGB value
83
77
  def hsl2rgb(hue, saturation, lightness)
84
78
  hue /= 360.0
85
79
  q_factor = lightness < 0.5 ? lightness * (1.0 + saturation) : (lightness + saturation) - (lightness * saturation)
86
- p_factor = 2.0 * lightness - q_factor
80
+ p_factor = (2.0 * lightness) - q_factor
87
81
 
88
- [hue + (1.0 / 3.0), hue, hue - (1.0 / 3.0)].map do |color|
89
- color += 1.0 if (color / 0.5) < 0.0
90
- color -= 1.0 if color > 1
82
+ [hue + ONE_THIRD, hue, hue - ONE_THIRD].map do |color|
83
+ color += 1.0 if color < 0.0
84
+ color -= 1.0 if color > 1.0
91
85
 
92
- color = if color < (1.0 / 6.0)
93
- p_factor + (q_factor - p_factor) * 6.0 * color
86
+ color = if color < ONE_SIXTH
87
+ p_factor + ((q_factor - p_factor) * 6.0 * color)
94
88
  elsif color < 0.5
95
89
  q_factor
96
- elsif color < (2.0 / 3.0)
97
- p_factor + (q_factor - p_factor) * 6.0 * ((2.0 / 3.0) - color)
90
+ elsif color < TWO_THIRDS
91
+ p_factor + ((q_factor - p_factor) * 6.0 * (TWO_THIRDS - color))
98
92
  else
99
93
  p_factor
100
94
  end
@@ -102,10 +96,6 @@ module ColorHash
102
96
  (color * 255.0).round
103
97
  end
104
98
  end
105
- # rubocop:enable Metrics/AbcSize
106
- # rubocop:enable Metrics/CyclomaticComplexity
107
- # rubocop:enable Metrics/PerceivedComplexity
108
- # rubocop:enable Metrics/MethodLength
109
99
 
110
100
  # Calculates an Hexadecimal color value from a given string.
111
101
  # Returns a 6 digits hex string starting with '#'.
@@ -113,15 +103,8 @@ module ColorHash
113
103
  rgb2hex(rgb(str))
114
104
  end
115
105
 
116
- # Convers a color specified by its RGB value to a hexadecimal color value.
117
106
  def rgb2hex(rgb)
118
- hex = "#"
119
- rgb.each do |c|
120
- hex += "0" if c < 16
121
- hex += c.to_s(16)
122
- end
123
-
124
- hex
107
+ format("#%02x%02x%02x", *rgb)
125
108
  end
126
109
 
127
110
  # Calculate a SHA2-256 based hash of the given string
@@ -142,9 +125,9 @@ module ColorHash
142
125
  str += "x"
143
126
  # Number.MAX_SAFE_INTEGER equals 9007199254740991
144
127
  max_safe = 9_007_199_254_740_991 / seed2
145
- str.each_codepoint.map do |c|
128
+ str.each_codepoint do |c|
146
129
  hash = (hash / seed2).floor if hash > max_safe
147
- hash = hash * seed + c
130
+ hash = (hash * seed) + c
148
131
  end
149
132
 
150
133
  hash
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ColorHash
4
- VERSION = "0.1.0"
4
+ VERSION = "1.0.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Bettenburg
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2022-12-15 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Generate a color based on the given string (in the HSL color space).
14
13
  email:
@@ -22,9 +21,9 @@ files:
22
21
  - CHANGELOG.md
23
22
  - Gemfile
24
23
  - Gemfile.lock
24
+ - Makefile
25
25
  - README.md
26
26
  - Rakefile
27
- - color_hash.gemspec
28
27
  - lib/color_hash.rb
29
28
  - lib/color_hash/generator.rb
30
29
  - lib/color_hash/version.rb
@@ -36,7 +35,7 @@ metadata:
36
35
  homepage_uri: https://github.com/kuyio/color_hash
37
36
  source_code_uri: https://github.com/kuyio/color_hash
38
37
  changelog_uri: https://github.com/kuyio/color_hash/CHANGELOG.md
39
- post_install_message:
38
+ rubygems_mfa_required: 'true'
40
39
  rdoc_options: []
41
40
  require_paths:
42
41
  - lib
@@ -44,15 +43,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - ">="
46
45
  - !ruby/object:Gem::Version
47
- version: 2.6.0
46
+ version: 3.4.0
48
47
  required_rubygems_version: !ruby/object:Gem::Requirement
49
48
  requirements:
50
49
  - - ">="
51
50
  - !ruby/object:Gem::Version
52
51
  version: '0'
53
52
  requirements: []
54
- rubygems_version: 3.3.17
55
- signing_key:
53
+ rubygems_version: 4.0.6
56
54
  specification_version: 4
57
55
  summary: Generate a color based on the given string.
58
56
  test_files: []
data/color_hash.gemspec DELETED
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/color_hash/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "color_hash"
7
- spec.version = ColorHash::VERSION
8
- spec.authors = ["Nicolas Bettenburg"]
9
- spec.email = ["nicbet@kuy.io"]
10
-
11
- spec.summary = "Generate a color based on the given string."
12
- spec.description = "Generate a color based on the given string (in the HSL color space)."
13
- spec.homepage = "https://github.com/kuyio/color_hash"
14
- spec.required_ruby_version = ">= 2.6.0"
15
-
16
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
-
18
- spec.metadata["homepage_uri"] = spec.homepage
19
- spec.metadata["source_code_uri"] = "https://github.com/kuyio/color_hash"
20
- spec.metadata["changelog_uri"] = "https://github.com/kuyio/color_hash/CHANGELOG.md"
21
-
22
- # Specify which files should be added to the gem when it is released.
23
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
- spec.files = Dir.chdir(__dir__) do
25
- `git ls-files -z`.split("\x0").reject do |f|
26
- (f == __FILE__) || f.match(%r{\A(?:(?:doc|bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
- end
28
- end
29
- spec.bindir = "exe"
30
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
32
- end