color_converters 0.1.1 → 0.1.2

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: c97c6fdaf99305ee413b3648f6c16b8fe9a83124696af3e3e161fae19d71fe19
4
- data.tar.gz: b0c6e84ebde615a1b7d044aaa85556e16e1ca9bfa0181232c238b74a1d80d25f
3
+ metadata.gz: 571bd439610154032f4532335702ecb175cd3b022b966843b81ebc26c12a5411
4
+ data.tar.gz: 33dad1ab16c74560c7fd4587392400002cc863ee16e77bff739e28577f1b9451
5
5
  SHA512:
6
- metadata.gz: 1c42e5f3097a878896c29b317856cfd3b9d3458b24ad66c69ac1cf550a50c7bd72e04c135157ef582d8f8ce0408500624f7776339c8949442ea41c1cfec77956
7
- data.tar.gz: 8a6310fd2eaa1b323236111ddb96732ad84fca43edfd4e39805afd614499c2afee09b481e81fdcb454187e45637c57770a3e4676c346238641aaf23e686220d4
6
+ metadata.gz: 6c9138a8fa458032dfcc2319a2d188a545e9042cfe740d168b737a5d984b4ec94501efce7d384a54baf3ea717384e6b9cc0fbebc8d085a2eb46c24879fa2cefb
7
+ data.tar.gz: 5cdd92b601b6458552e617413ff4cd1b884571009d5d565e727e47d57da202feb9e9b4b6a6e8ac0fd2592b612b055bc9aa78cbe530f85336bc5fb0d2a07ed236
data/README.md CHANGED
@@ -63,10 +63,10 @@ color = ColorConverters::Color.new(c: 74, m: 58, y: 22, k: 3)
63
63
  color = ColorConverters::Color.new(x: 16, y: 44, z: 32)
64
64
 
65
65
  # from cielab
66
- color = ColorConverters::Color.new(l: 16, a: 44, b: 32)
66
+ color = ColorConverters::Color.new(l: 16, a: 44, b: 32, space: :cie)
67
67
 
68
- # from oklch
69
- color = ColorConverters::Color.new(l: 16, c: 44, h: 32)
68
+ # from cielch
69
+ color = ColorConverters::Color.new(l: 16, c: 44, h: 32, space: :cie)
70
70
 
71
71
  # from textual color
72
72
  color = ColorConverters::Color.new("blue")
@@ -109,7 +109,7 @@ color.xyz
109
109
  color.cielab
110
110
  => {:l=>52.47, :a=>-4.08, :b=>-32.19}
111
111
 
112
- color.oklch
112
+ color.cielch
113
113
  => {:l=>52.47, :c=>32.45, :h=>262.78}
114
114
 
115
115
  color.hex
@@ -121,6 +121,15 @@ color.name
121
121
 
122
122
  ## Options
123
123
 
124
+ ### space
125
+
126
+ As there are certain color spaces that use the same letter keys, there needed to be a way to different between those space.
127
+ The space parameter allows that, with examples in the usage code above
128
+
129
+ ```ruby
130
+ ColorConverters::Color.new(l: 64, a: 28, b: -15, space: :cie)
131
+ ```
132
+
124
133
  ### limit_override
125
134
 
126
135
  By default all values are checked to be within the expected number ranges, i.e.; rgb between 0-255 each.
@@ -26,6 +26,8 @@ module ColorConverters
26
26
  def initialize(color_input, limit_override = false)
27
27
  @original_value = color_input
28
28
 
29
+ # self.clamp_input(color_input) if limit_clamp == true
30
+
29
31
  if limit_override == false && !self.validate_input(color_input)
30
32
  raise InvalidColorError # validation method is defined in each convertor
31
33
  end
@@ -72,13 +74,13 @@ module ColorConverters
72
74
  end
73
75
 
74
76
  def cielab
75
- l, a, b = CielabConverter.xyz_to_lab(XyzConverter.rgb_to_xyz(self.rgb_array_frac))
77
+ l, a, b = CielabConverter.xyz_to_cielab(XyzConverter.rgb_to_xyz(self.rgb_array_frac))
76
78
 
77
79
  { l: l.round(OUTPUT_DP), a: a.round(OUTPUT_DP), b: b.round(OUTPUT_DP) }
78
80
  end
79
81
 
80
- def oklch
81
- l, c, h = OklchConverter.lab_to_lch(CielabConverter.xyz_to_lab(XyzConverter.rgb_to_xyz(self.rgb_array_frac)))
82
+ def cielch
83
+ l, c, h = CielchConverter.cielab_to_cielch(CielabConverter.xyz_to_cielab(XyzConverter.rgb_to_xyz(self.rgb_array_frac)))
82
84
 
83
85
  { l: l.round(OUTPUT_DP), c: c.round(OUTPUT_DP), h: h.round(OUTPUT_DP) }
84
86
  end
@@ -1,7 +1,7 @@
1
1
  module ColorConverters
2
2
  class Color
3
3
  extend Forwardable
4
- def_delegators :@converter, :rgb, :hex, :hsl, :hsv, :hsb, :cmyk, :xyz, :cielab, :oklch, :name, :alpha
4
+ def_delegators :@converter, :rgb, :hex, :hsl, :hsv, :hsb, :cmyk, :xyz, :cielab, :cielch, :name, :alpha
5
5
 
6
6
  def initialize(color)
7
7
  @converter = BaseConverter.factory(color)
@@ -3,7 +3,7 @@ module ColorConverters
3
3
  def self.matches?(color_input)
4
4
  return false unless color_input.is_a?(Hash)
5
5
 
6
- color_input.keys - [:l, :a, :b] == []
6
+ color_input.keys - [:l, :a, :b, :space] == [] && color_input[:space].to_s == 'cie'
7
7
  end
8
8
 
9
9
  def self.bounds
@@ -18,11 +18,11 @@ module ColorConverters
18
18
  end
19
19
 
20
20
  def input_to_rgba(color_input)
21
- xyz_hash = CielabConverter.lab_to_xyz(color_input)
21
+ xyz_hash = CielabConverter.cielab_to_xyz(color_input)
22
22
  XyzConverter.new(xyz_hash, limit_override: true).rgba
23
23
  end
24
24
 
25
- def self.lab_to_xyz(color_input)
25
+ def self.cielab_to_xyz(color_input)
26
26
  l = color_input[:l].to_f
27
27
  a = color_input[:a].to_f
28
28
  b = color_input[:b].to_f
@@ -48,7 +48,7 @@ module ColorConverters
48
48
  { x: x, y: y, z: z }
49
49
  end
50
50
 
51
- def self.xyz_to_lab(xyz_array)
51
+ def self.xyz_to_cielab(xyz_array)
52
52
  x, y, z = xyz_array
53
53
 
54
54
  # The D65 standard illuminant white point
@@ -1,9 +1,9 @@
1
1
  module ColorConverters
2
- class OklchConverter < BaseConverter
2
+ class CielchConverter < BaseConverter
3
3
  def self.matches?(color_input)
4
4
  return false unless color_input.is_a?(Hash)
5
5
 
6
- color_input.keys - [:l, :c, :h] == []
6
+ color_input.keys - [:l, :c, :h, :space] == [] && color_input[:space].to_s == 'cie'
7
7
  end
8
8
 
9
9
  def self.bounds
@@ -13,17 +13,17 @@ module ColorConverters
13
13
  private
14
14
 
15
15
  def validate_input(color_input)
16
- bounds = OklchConverter.bounds
16
+ bounds = CielchConverter.bounds
17
17
  color_input[:l].to_f.between?(*bounds[:l]) && color_input[:c].to_f.between?(*bounds[:c]) && color_input[:h].to_f.between?(*bounds[:h])
18
18
  end
19
19
 
20
20
  def input_to_rgba(color_input)
21
- lab_hash = OklchConverter.lch_to_lab(color_input)
22
- xyz_hash = CielabConverter.lab_to_xyz(lab_hash)
21
+ lab_hash = CielchConverter.cielch_to_cielab(color_input)
22
+ xyz_hash = CielabConverter.cielab_to_xyz(lab_hash)
23
23
  XyzConverter.new(xyz_hash, limit_override: true).rgba
24
24
  end
25
25
 
26
- def self.lch_to_lab(color_input)
26
+ def self.cielch_to_cielab(color_input)
27
27
  l = color_input[:l].to_f
28
28
  c = color_input[:c].to_f
29
29
  h = color_input[:h].to_f
@@ -36,7 +36,7 @@ module ColorConverters
36
36
  { l: l, a: a, b: b }
37
37
  end
38
38
 
39
- def self.lab_to_lch(lab_array)
39
+ def self.cielab_to_cielch(lab_array)
40
40
  l, aa, bb = lab_array
41
41
 
42
42
  c = ((aa**2) + (bb**2))**0.5
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ColorConverters
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -16,7 +16,7 @@ require 'color_converters/converters/hsv_converter'
16
16
  require 'color_converters/converters/cmyk_converter'
17
17
  require 'color_converters/converters/xyz_converter'
18
18
  require 'color_converters/converters/cielab_converter'
19
- require 'color_converters/converters/oklch_converter'
19
+ require 'color_converters/converters/cielch_converter'
20
20
 
21
21
  require 'color_converters/converters/name_converter'
22
22
  require 'color_converters/converters/null_converter'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_converters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Louis Davis
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-06-25 00:00:00.000000000 Z
10
+ date: 2025-06-26 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -36,6 +36,7 @@ files:
36
36
  - lib/color_converters/base_converter.rb
37
37
  - lib/color_converters/color.rb
38
38
  - lib/color_converters/converters/cielab_converter.rb
39
+ - lib/color_converters/converters/cielch_converter.rb
39
40
  - lib/color_converters/converters/cmyk_converter.rb
40
41
  - lib/color_converters/converters/hex_converter.rb
41
42
  - lib/color_converters/converters/hsl_converter.rb
@@ -43,7 +44,6 @@ files:
43
44
  - lib/color_converters/converters/hsv_converter.rb
44
45
  - lib/color_converters/converters/name_converter.rb
45
46
  - lib/color_converters/converters/null_converter.rb
46
- - lib/color_converters/converters/oklch_converter.rb
47
47
  - lib/color_converters/converters/rgb_converter.rb
48
48
  - lib/color_converters/converters/rgb_string_converter.rb
49
49
  - lib/color_converters/converters/xyz_converter.rb