color_conversion 0.1.0 → 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 67ef203f22ffbece2c150be570dcd841c9ea476da8352afaa41b1ea1988ca7b9
4
+ data.tar.gz: 17f62d21d1073db851c7d0e732b32d1f3b36637ae27bbf781a3e869c58c65dad
5
+ SHA512:
6
+ metadata.gz: 2dbacd4819c95094cfc6a296b1503a8950b7fdf9a50b3eba26cbd3613a8b07d0c2e0f257db45e202d4081f90944e60f1045f0e8569dc6456c66475ab1e39313c
7
+ data.tar.gz: 98beb5c98f321f891af4f06d49bd6b629417a886894c2e1d803335daf6e960d3c17dc31190f4b1734e0d8cef8ceec399f63b613be4cbc2564719a6bf812e1c35
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in color_parser.gemspec
4
2
  gemspec
data/README.md CHANGED
@@ -4,51 +4,67 @@ This gem provides conversions for colors to and from Hex, RGB, and HSL.
4
4
 
5
5
  ## Examples
6
6
 
7
- Create a new color:
7
+ Initialize a color:
8
8
  ```ruby
9
9
  # from hex
10
- color = Color.new("#FFFFFF")
11
- color = Color.new("#FFF")
10
+ color = Color.new("#3366cc")
11
+ color = Color.new("#36c")
12
12
 
13
- # from rgb and rgba
14
- color = Color.new(r: 255, g: 255, b: 255)
15
- color = Color.new(r: 255, g: 255, b: 255, a: 0.5)
13
+ # from rgb(a)
14
+ color = Color.new(r: 51, g: 102, b: 204)
15
+ color = Color.new(r: 51, g: 102, b: 204, a: 0.5)
16
16
 
17
- # from hsl and hsla
18
- color = Color.new(h: 0, s: 100, l: 100)
19
- color = Color.new(h: 0, s: 100, l: 100, a: 0.5)
17
+ # from hsl(a)
18
+ color = Color.new(h: 225, s: 73, l: 57)
19
+ color = Color.new(h: 225, s: 73, l: 57, a: 0.5)
20
+
21
+ # from hsv/hsb
22
+ color = Color.new(h: 220, s: 75, v: 80)
23
+ color = Color.new(h: 220, s: 75, b: 80)
24
+
25
+ # from cmyk
26
+ color = Color.new(c: 74, m: 58, y: 22, k: 3)
20
27
 
21
28
  # from textual color
22
- color = Color.new("white")
29
+ color = Color.new("blue")
23
30
 
24
- # from a css declaration
25
- color = Color.new("rgb(255,255,255)")
26
- color = Color.new("hsl(0,100%,100%)")
31
+ # from a css rgb(a) string
32
+ color = Color.new("rgb(51, 102, 204)")
33
+ color = Color.new("rgba(51, 102, 204, 0.5)")
34
+
35
+ # from a css hsl(a) string
36
+ color = Color.new("hsl(225, 73%, 57%)")
37
+ color = Color.new("hsl(225, 73%, 57%, 0.5)")
27
38
  ```
28
39
 
40
+ Conversions
29
41
 
30
- Convert to RGB
31
42
  ```ruby
32
- Color.new("white").rgb
33
- => {:r=>255, :g=>255, :b=>255}
34
- ```
43
+ color = Color.new(r: 70, g: 130, b: 180, a: 0.5)
35
44
 
36
- Convert to Hex
37
- ```ruby
38
- Color.new("white").hex
39
- => "#FFFFFF"
40
- ```
45
+ color.alpha
46
+ => 0.5
41
47
 
42
- Convert to HSL
43
- ```ruby
44
- Color.new("white").hsl
45
- => {:h=>0, :s=>100, :l=>100}
46
- ```
48
+ color.rgb
49
+ => {:r=>70, :g=>130, :b=>180}
47
50
 
48
- Convert to Name
49
- ```ruby
50
- Color.new("#FFFFFF").name
51
- => "white"
51
+ color.hsl
52
+ => {:h=>207, :s=>44, :l=>49}
53
+
54
+ color.hsv
55
+ => {:h=>207, :s=>61, :v=>71}
56
+
57
+ color.hsb
58
+ => {:h=>207, :s=>61, :b=>71}
59
+
60
+ color.cmyk
61
+ => {:c=>61, :m=>28, :y=>0, :k=>29}
62
+
63
+ color.hex
64
+ => "#4682b4"
65
+
66
+ color.name
67
+ => "steelblue"
52
68
  ```
53
69
 
54
70
 
@@ -57,7 +73,7 @@ Color.new("#FFFFFF").name
57
73
  To install ColorConversion, add the gem to your Gemfile:
58
74
 
59
75
  ```ruby
60
- gem "color_conversion", "~> 0.1.0"
76
+ gem "color_conversion"
61
77
  ```
62
78
 
63
79
  ## LICENSE
@@ -1,10 +1,16 @@
1
1
  module ColorConversion
2
2
  class Color
3
3
  extend Forwardable
4
- def_delegators :@converter, :rgb, :hex, :hsl, :hsv, :hsb, :cymk, :alpha
4
+ def_delegators :@converter, :rgb, :hex, :hsl, :hsv, :hsb, :cmyk, :alpha
5
5
 
6
6
  def initialize(color)
7
7
  @converter = ColorConverter.factory(color)
8
8
  end
9
+
10
+ def ==(other)
11
+ return false unless other.is_a?(Color)
12
+
13
+ rgb == other.rgb && alpha == other.alpha
14
+ end
9
15
  end
10
- end
16
+ end
@@ -33,65 +33,15 @@ module ColorConversion
33
33
  end
34
34
 
35
35
  def hsl
36
- r = @rgba[:r] / 255.0
37
- g = @rgba[:g] / 255.0
38
- b = @rgba[:b] / 255.0
39
- min = [r, g, b].min
40
- max = [r, g, b].max
41
- delta = max - min
36
+ @r, @g, @b = rgb_array_frac
42
37
 
43
- h = if max == min
44
- 0
45
- elsif r == max
46
- (g - b) / delta
47
- elsif g == max
48
- 2 + (b - r) / delta
49
- elsif b == max
50
- 4 + (r - g) / delta
51
- end
52
-
53
- h = [h * 60, 360].min
54
- h += 360 if h < 0
55
- l = (min + max) / 2.0
56
-
57
- s = if (max == min)
58
- 0
59
- elsif (l <= 0.5)
60
- delta / (max + min)
61
- else
62
- delta / (2.0 - max - min)
63
- end
64
-
65
- {h: h.round, s: (s * 100).round, l: (l * 100).round}
38
+ {h: hue, s: hsl_saturation, l: hsl_lightness}
66
39
  end
67
-
68
- def hsv
69
- r = @rgba[:r].to_f
70
- g = @rgba[:g].to_f
71
- b = @rgba[:b].to_f
72
- min = [r, g, b].min
73
-
74
- max = [r, g, b].max
75
- delta = (max - min).to_f
76
-
77
- s = max == 0 ? 0 : (delta / max * 1000) / 10.0
78
-
79
- h = if max == min
80
- 0
81
- elsif r == max
82
- (g - b) / delta
83
- elsif g == max
84
- 2 + (b - r) / delta
85
- elsif b == max
86
- 4 + (r - g) / delta
87
- end
88
-
89
- h = [h * 60, 360].min
90
- h += 360 if h < 0
91
40
 
92
- v = ((max / 255.0) * 1000) / 10.0
41
+ def hsv
42
+ @r, @g, @b = rgb_array
93
43
 
94
- {h: h.round, s: s.round, v: v.round}
44
+ {h: hue, s: hsv_saturation, v: hsv_value}
95
45
  end
96
46
 
97
47
  def hsb
@@ -101,14 +51,12 @@ module ColorConversion
101
51
  end
102
52
 
103
53
  def cmyk
104
- r = @rgba[:r] / 255.0
105
- g = @rgba[:g] / 255.0
106
- b = @rgba[:b] / 255.0
54
+ @r, @g, @b = rgb_array_frac
107
55
 
108
- k = [1.0 - r, 1.0 - g, 1.0 - b].min
109
- c = (1.0 - r - k) / (1.0 - k)
110
- m = (1.0 - g - k) / (1.0 - k)
111
- y = (1.0 - b - k) / (1.0 - k)
56
+ k = [1.0 - @r, 1.0 - @g, 1.0 - @b].min
57
+ c = (1.0 - @r - k) / (1.0 - k)
58
+ m = (1.0 - @g - k) / (1.0 - k)
59
+ y = (1.0 - @b - k) / (1.0 - k)
112
60
 
113
61
  {c: (c * 100).round,
114
62
  m: (m * 100).round,
@@ -119,6 +67,78 @@ module ColorConversion
119
67
  def alpha
120
68
  @rgba[:a]
121
69
  end
70
+
71
+ def name
72
+ NameConverter.name_for_rgb(rgb)
73
+ end
74
+
75
+
76
+ protected
77
+
78
+ def rgb_array
79
+ [@rgba[:r].to_f, @rgba[:g].to_f, @rgba[:b].to_f]
80
+ end
81
+
82
+ def rgb_array_frac
83
+ [@rgba[:r] / 255.0, @rgba[:g] / 255.0, @rgba[:b] / 255.0]
84
+ end
85
+
86
+ def min
87
+ [@r, @g, @b].min
88
+ end
89
+
90
+ def max
91
+ [@r, @g, @b].max
92
+ end
93
+
94
+ def delta
95
+ max - min
96
+ end
97
+
98
+ def hue
99
+ h = if max == min
100
+ 0
101
+ elsif @r == max
102
+ (@g - @b) / delta
103
+ elsif @g == max
104
+ 2 + (@b - @r) / delta
105
+ elsif @b == max
106
+ 4 + (@r - @g) / delta
107
+ end
108
+
109
+ h = [h * 60, 360].min
110
+ h += 360 if h < 0
111
+ h.round
112
+ end
113
+
114
+ # hsv
115
+ def hsv_saturation
116
+ sat = max == 0 ? 0 : (delta / max * 1000) / 10.0
117
+ sat.round
118
+ end
119
+
120
+ def hsv_value
121
+ val = ((max / 255.0) * 1000) / 10.0
122
+ val.round
123
+ end
124
+
125
+ # hsl
126
+ def hsl_saturation
127
+ s = if max == min
128
+ 0
129
+ elsif hsl_lightness / 100.0 <= 0.5
130
+ delta / (max + min)
131
+ else
132
+ delta / (2.0 - max - min)
133
+ end
134
+
135
+ (s * 100).round
136
+ end
137
+
138
+ def hsl_lightness
139
+ light = (min + max) / 2.0 * 100
140
+ light.round
141
+ end
122
142
 
123
143
  end
124
144
  end
@@ -15,7 +15,7 @@ module ColorConversion
15
15
  l = hsl[:l].to_s.gsub(/[^0-9\.]/, "").to_f / 100.0
16
16
  a = hsl[:a] ? hsl[:a].to_s.gsub(/[^0-9\.]/, "").to_f : 1.0
17
17
 
18
- return [l * 255, l * 255, l * 255] if s == 0
18
+ return greyscale(l, a) if s == 0
19
19
 
20
20
  t2 = if l < 0.5
21
21
  l * (1 + s)
@@ -47,5 +47,11 @@ module ColorConversion
47
47
 
48
48
  {r: rgb[0], g: rgb[1], b: rgb[2], a: a}
49
49
  end
50
+
51
+ def greyscale(luminosity, alpha)
52
+ rgb_equal_value = (luminosity * 255).round
53
+ { r: rgb_equal_value, g: rgb_equal_value, b: rgb_equal_value, a: alpha }
54
+ end
55
+
50
56
  end
51
57
  end
@@ -6,6 +6,11 @@ module ColorConversion
6
6
 
7
7
  color_names.include?(color.downcase.to_sym)
8
8
  end
9
+
10
+ def self.name_for_rgb(rgb)
11
+ name = color_names.find {|k,v| v == [rgb[:r], rgb[:g], rgb[:b]] }
12
+ name[0].to_s if name
13
+ end
9
14
 
10
15
  private
11
16
 
@@ -13,7 +18,7 @@ module ColorConversion
13
18
  rgb = self.class.color_names[name.downcase.to_sym]
14
19
  {r: rgb[0], g: rgb[1], b: rgb[2], a: 1.0}
15
20
  end
16
-
21
+
17
22
  def self.color_names
18
23
  {aliceblue: [240,248,255],
19
24
  antiquewhite: [250,235,215],
@@ -1,3 +1,3 @@
1
1
  module ColorConversion
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -45,8 +45,8 @@ describe ColorConverter do
45
45
  end
46
46
  end
47
47
 
48
- describe ".cymk" do
49
- it "converts color to cymk" do
48
+ describe ".cmyk" do
49
+ it "converts color to cmyk" do
50
50
  conv = RgbConverter.new(r: 64, g: 104, b: 193)
51
51
 
52
52
  cmyk = {c: 67, m: 46, y: 0, k: 24}
@@ -54,6 +54,18 @@ describe ColorConverter do
54
54
  end
55
55
  end
56
56
 
57
+ describe ".name" do
58
+ it "converts color to name" do
59
+ conv = RgbConverter.new(r: 255, g: 0, b: 0)
60
+ expect(conv.name).to eq "red"
61
+ end
62
+
63
+ it "returns nil if no name found" do
64
+ conv = RgbConverter.new(r: 255, g: 0, b: 1)
65
+ expect(conv.name).to be_nil
66
+ end
67
+ end
68
+
57
69
  describe ".alpha" do
58
70
  it "finds alpha for color" do
59
71
  conv = RgbConverter.new(r: 51, g: 102, b: 204, a: 0.5)
data/spec/color_spec.rb CHANGED
@@ -1,94 +1,142 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Color do
4
-
5
- describe ".new with color string" do
3
+ describe Color do
6
4
 
7
- it "should initialize color by lower hex" do
5
+ describe ".new with color string" do
6
+
7
+ it "should initialize color by lower hex" do
8
8
  color = Color.new("#3366cc")
9
9
  expect(color.rgb).to eq(r: 51, g: 102, b: 204)
10
10
  end
11
11
 
12
- it "should initialize color by hex with hash" do
12
+ it "should initialize color by hex with hash" do
13
13
  color = Color.new("#3366CC")
14
14
  expect(color.rgb).to eq(r: 51, g: 102, b: 204)
15
15
  end
16
16
 
17
- it "should initialize color by short hex" do
17
+ it "should initialize color by short hex" do
18
18
  color = Color.new("#36C")
19
19
  expect(color.rgb).to eq(r: 51, g: 102, b: 204)
20
20
  end
21
21
 
22
- it "should initialize color by rgb string" do
22
+ it "should initialize color by rgb string" do
23
23
  color = Color.new("rgb(51, 102, 204)")
24
24
  expect(color.rgb).to eq(r: 51, g: 102, b: 204)
25
25
  end
26
26
 
27
- it "should initialize color by rgba string" do
27
+ it "should initialize color by rgba string" do
28
28
  color = Color.new("rgba(51, 102, 204, 0.2)")
29
29
  expect(color.rgb).to eq(r: 51, g: 102, b: 204)
30
30
  expect(color.alpha).to eq 0.2
31
31
  end
32
32
 
33
- it "should initialize color by hsl string" do
33
+ it "should initialize color by hsl string" do
34
34
  color = Color.new("hsl(225, 73%, 57%)")
35
35
  expect(color.rgb).to eq(r: 65, g: 105, b: 225)
36
36
  end
37
37
 
38
- it "should initialize color by hsla string" do
39
- color = Color.new("hsla(225, 73%, 57%, 0.5)")
38
+ it "should initialize color by hsla string" do
39
+ color = Color.new("hsla(225, 73%, 57%, 0.5)")
40
40
  expect(color.rgb).to eq(r: 65, g: 105, b: 225)
41
41
  expect(color.alpha).to eq 0.5
42
42
  end
43
-
44
- it "should initialize color by textual string" do
43
+
44
+ it "should initialize color by textual string" do
45
45
  color = Color.new("royalblue")
46
46
  expect(color.rgb).to eq(r: 65, g: 105, b: 225)
47
47
  end
48
48
 
49
- it "should initialize color by textual string case" do
49
+ it "should initialize color by textual string case" do
50
50
  color = Color.new("RoyalBlue")
51
51
  expect(color.rgb).to eq(r: 65, g: 105, b: 225)
52
52
  end
53
53
  end
54
54
 
55
55
 
56
- describe ".new" do
57
- it "should initialize color by rgb" do
56
+ describe ".new" do
57
+ it "should initialize color by rgb" do
58
58
  color = Color.new(r: 51, g: 102, b: 204)
59
59
  expect(color.rgb).to eq(r: 51, g: 102, b: 204)
60
60
  end
61
61
 
62
- it "should initialize color by rgba" do
62
+ it "should initialize color by rgba" do
63
63
  color = Color.new(r: 51, g: 102, b: 204, a: 0.5)
64
64
  expect(color.rgb).to eq(r: 51, g: 102, b: 204)
65
65
  expect(color.alpha).to eq 0.5
66
66
  end
67
67
 
68
- it "should initialize color by hsl" do
68
+ it "should initialize color by hsl" do
69
69
  color = Color.new(h: 225, s: 73, l: 57)
70
70
  expect(color.rgb).to eq(r: 65, g: 105, b: 225)
71
71
  end
72
72
 
73
- it "should initialize color by hsla" do
73
+ it "should initialize color by hsla" do
74
74
  color = Color.new(h: 225, s: 73, l: 57, a: 0.5)
75
75
  expect(color.rgb).to eq(r: 65, g: 105, b: 225)
76
76
  expect(color.alpha).to eq 0.5
77
77
  end
78
-
79
- it "should initialize color by hsv" do
78
+
79
+ it "should initialize color by hsv" do
80
80
  color = Color.new(h: 220, s: 75, v: 80)
81
81
  expect(color.rgb).to eq(r: 51, g: 102, b: 204)
82
82
  end
83
83
 
84
- it "should initialize color by hsb" do
84
+ it "should initialize color by hsb" do
85
85
  color = Color.new(h: 220, s: 75, b: 80)
86
86
  expect(color.rgb).to eq(r: 51, g: 102, b: 204)
87
87
  end
88
88
 
89
- it "should initialize color by cmyk" do
89
+ it "should initialize color by cmyk" do
90
90
  color = Color.new(c: 74, m: 58, y: 22, k: 3)
91
91
  expect(color.rgb).to eq(r: 64, g: 104, b: 193)
92
92
  end
93
93
  end
94
+
95
+ describe ".==" do
96
+ it "should be equal when same color" do
97
+ color_1 = Color.new("#3366cc")
98
+ color_2 = Color.new("#3366cc")
99
+
100
+ expect(color_1).to eq(color_2)
101
+ end
102
+
103
+ it "should be equal when logically same color" do
104
+ color_1 = Color.new("#3366cc")
105
+ color_2 = Color.new(r: 51, g: 102, b: 204)
106
+
107
+ expect(color_1).to eq(color_2)
108
+ end
109
+
110
+ it "should be equal when same color and alpha" do
111
+ color_1 = Color.new(r: 51, g: 102, b: 204, a: 0.2)
112
+ color_2 = Color.new("rgba(51, 102, 204, 0.2)")
113
+
114
+ expect(color_1).to eq(color_2)
115
+ end
116
+
117
+ it "should not be equal when same color but not same alpha" do
118
+ color_1 = Color.new(r: 51, g: 102, b: 204, a: 0.2)
119
+ color_2 = Color.new(r: 51, g: 102, b: 204, a: 0.2)
120
+
121
+ expect(color_1).to eq(color_2)
122
+ end
123
+
124
+ it "should not be equal when not same object" do
125
+ color_1 = Color.new(r: 51, g: 102, b: 204, a: 0.4)
126
+ color_like = Struct.new(:r, :g, :b, :alpha, keyword_init: true) do
127
+ def rgb
128
+ {r: r, g: g, b: b}
129
+ end
130
+ end
131
+ color_2 = color_like.new(r: 51, g: 102, b: 204, alpha: 0.4)
132
+
133
+ expect(color_1).not_to eq(color_2)
134
+ end
135
+
136
+ it "should not be equal when other is nil" do
137
+ color_1 = Color.new(r: 51, g: 102, b: 204, a: 0.4)
138
+
139
+ expect(color_1).not_to eq(nil)
140
+ end
141
+ end
94
142
  end
@@ -3,15 +3,15 @@ require 'spec_helper'
3
3
  describe CmykConverter do
4
4
  describe ".matches?" do
5
5
  it "should match args with cmyk hash" do
6
- expect(CmykConverter.matches?(c: 87, m: 69, y: 13, k: 1)).to be_true
6
+ expect(CmykConverter.matches?(c: 87, m: 69, y: 13, k: 1)).to be true
7
7
  end
8
8
 
9
9
  it "should not match args without cmyk hash" do
10
- expect(CmykConverter.matches?(h: 225, s: 73, v: 57)).to be_false
10
+ expect(CmykConverter.matches?(h: 225, s: 73, v: 57)).to be false
11
11
  end
12
12
 
13
13
  it "should not match a string" do
14
- expect(CmykConverter.matches?("#ffffff")).to be_false
14
+ expect(CmykConverter.matches?("#ffffff")).to be false
15
15
  end
16
16
  end
17
17
 
@@ -3,23 +3,23 @@ require 'spec_helper'
3
3
  describe HexConverter do
4
4
  describe ".matches?" do
5
5
  it "should match args with hex string" do
6
- expect(HexConverter.matches?("#FFFFFF")).to be_true
6
+ expect(HexConverter.matches?("#FFFFFF")).to be true
7
7
  end
8
8
 
9
9
  it "should match args with short hex string" do
10
- expect(HexConverter.matches?("#FFF")).to be_true
10
+ expect(HexConverter.matches?("#FFF")).to be true
11
11
  end
12
12
 
13
13
  it "should match args with lower case hex string" do
14
- expect(HexConverter.matches?("#ffffff")).to be_true
14
+ expect(HexConverter.matches?("#ffffff")).to be true
15
15
  end
16
16
 
17
17
  it "should not match args without hex string" do
18
- expect(HexConverter.matches?("asdf")).to be_false
18
+ expect(HexConverter.matches?("asdf")).to be false
19
19
  end
20
20
 
21
21
  it "should not match args without hex string" do
22
- expect(HexConverter.matches?(h: 225, s: 73, l: 57)).to be_false
22
+ expect(HexConverter.matches?(h: 225, s: 73, l: 57)).to be false
23
23
  end
24
24
  end
25
25
 
@@ -30,4 +30,4 @@ describe HexConverter do
30
30
  expect(conv.rgba).to eq rgba
31
31
  end
32
32
  end
33
- end
33
+ end
@@ -3,19 +3,19 @@ require 'spec_helper'
3
3
  describe HslConverter do
4
4
  describe ".matches?" do
5
5
  it "should match args with hsl hash" do
6
- expect(HslConverter.matches?(h: 225, s: 73, l: 57)).to be_true
6
+ expect(HslConverter.matches?(h: 225, s: 73, l: 57)).to be true
7
7
  end
8
8
 
9
9
  it "should match args with hsla hash" do
10
- expect(HslConverter.matches?(h: 225, s: 73, l: 57, a: 0.5)).to be_true
10
+ expect(HslConverter.matches?(h: 225, s: 73, l: 57, a: 0.5)).to be true
11
11
  end
12
12
 
13
13
  it "should not match args without hsl hash" do
14
- expect(HslConverter.matches?(h: 225, s: 73, v: 57)).to be_false
14
+ expect(HslConverter.matches?(h: 225, s: 73, v: 57)).to be false
15
15
  end
16
16
 
17
17
  it "should not match a string" do
18
- expect(HslConverter.matches?("#ffffff")).to be_false
18
+ expect(HslConverter.matches?("#ffffff")).to be false
19
19
  end
20
20
  end
21
21
 
@@ -37,5 +37,11 @@ describe HslConverter do
37
37
  rgba = {r: 65, g: 105, b: 225, a: 0.5}
38
38
  expect(conv.rgba).to eq rgba
39
39
  end
40
+
41
+ it 'should return equal values when saturation is 0' do
42
+ conv = HslConverter.new(h: "225", s: "0%", l: "20%", a: "0.5")
43
+ rgba = {r: 51, g: 51, b: 51, a: 0.5}
44
+ expect(conv.rgba).to eq rgba
45
+ end
40
46
  end
41
- end
47
+ end
@@ -3,15 +3,15 @@ require 'spec_helper'
3
3
  describe HslStringConverter do
4
4
  describe ".matches?" do
5
5
  it "should match args with hsl string" do
6
- expect(HslStringConverter.matches?("hsl(225, 73%, 57%)")).to be_true
6
+ expect(HslStringConverter.matches?("hsl(225, 73%, 57%)")).to be true
7
7
  end
8
8
 
9
9
  it "should match args with hsla string" do
10
- expect(HslStringConverter.matches?("hsla(225, 73%, 57%, 0.5)")).to be_true
10
+ expect(HslStringConverter.matches?("hsla(225, 73%, 57%, 0.5)")).to be true
11
11
  end
12
12
 
13
13
  it "should not match args without hsl string" do
14
- expect(HslStringConverter.matches?(h: 225, s: 73, l: 57)).to be_false
14
+ expect(HslStringConverter.matches?(h: 225, s: 73, l: 57)).to be false
15
15
  end
16
16
  end
17
17
 
@@ -28,4 +28,4 @@ describe HslStringConverter do
28
28
  expect(conv.rgba).to eq rgba
29
29
  end
30
30
  end
31
- end
31
+ end
@@ -3,19 +3,19 @@ require 'spec_helper'
3
3
  describe HsvConverter do
4
4
  describe ".matches?" do
5
5
  it "should match args with hsv hash" do
6
- expect(HsvConverter.matches?(h: 225, s: 73, v: 57)).to be_true
6
+ expect(HsvConverter.matches?(h: 225, s: 73, v: 57)).to be true
7
7
  end
8
8
 
9
9
  it "should match args with hsb hash" do
10
- expect(HsvConverter.matches?(h: 225, s: 73, b: 57)).to be_true
10
+ expect(HsvConverter.matches?(h: 225, s: 73, b: 57)).to be true
11
11
  end
12
12
 
13
13
  it "should not match args without hsv hash" do
14
- expect(HsvConverter.matches?(h: 225, s: 73, l: 57)).to be_false
14
+ expect(HsvConverter.matches?(h: 225, s: 73, l: 57)).to be false
15
15
  end
16
16
 
17
17
  it "should not match a string" do
18
- expect(HsvConverter.matches?("#ffffff")).to be_false
18
+ expect(HsvConverter.matches?("#ffffff")).to be false
19
19
  end
20
20
  end
21
21
 
@@ -33,4 +33,4 @@ describe HsvConverter do
33
33
  end
34
34
 
35
35
  end
36
- end
36
+ end
@@ -3,16 +3,16 @@ require 'spec_helper'
3
3
  describe NameConverter do
4
4
  describe ".matches?" do
5
5
  it "should match args with name string" do
6
- expect(NameConverter.matches?("blue")).to be_true
6
+ expect(NameConverter.matches?("blue")).to be true
7
7
  end
8
8
 
9
9
  it "should match args with color insensitive string" do
10
- expect(NameConverter.matches?("RoyalBlue")).to be_true
11
- expect(NameConverter.matches?("royalblue")).to be_true
10
+ expect(NameConverter.matches?("RoyalBlue")).to be true
11
+ expect(NameConverter.matches?("royalblue")).to be true
12
12
  end
13
13
 
14
14
  it "should not match args without name string" do
15
- expect(NameConverter.matches?("#ffffff")).to be_false
15
+ expect(NameConverter.matches?("#ffffff")).to be false
16
16
  end
17
17
  end
18
18
 
@@ -23,4 +23,4 @@ describe NameConverter do
23
23
  expect(conv.rgba).to eq rgba
24
24
  end
25
25
  end
26
- end
26
+ end
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe NullConverter do
4
4
  describe ".matches?" do
5
5
  it "should always match" do
6
- expect(NullConverter.matches?("blue")).to be_true
7
- expect(NullConverter.matches?(r: 51, g: 102, b: 204)).to be_true
6
+ expect(NullConverter.matches?("blue")).to be true
7
+ expect(NullConverter.matches?(r: 51, g: 102, b: 204)).to be true
8
8
  end
9
9
  end
10
10
 
@@ -16,4 +16,4 @@ describe NullConverter do
16
16
  }.to raise_error(InvalidColorError)
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -3,19 +3,19 @@ require 'spec_helper'
3
3
  describe RgbConverter do
4
4
  describe ".matches?" do
5
5
  it "should match args with rgb hash" do
6
- expect(RgbConverter.matches?(r: 51, g: 102, b: 204)).to be_true
6
+ expect(RgbConverter.matches?(r: 51, g: 102, b: 204)).to be true
7
7
  end
8
8
 
9
9
  it "should match args with rgba hash" do
10
- expect(RgbConverter.matches?(r: 51, g: 102, b: 204, a: 0.5)).to be_true
10
+ expect(RgbConverter.matches?(r: 51, g: 102, b: 204, a: 0.5)).to be true
11
11
  end
12
12
 
13
13
  it "should not match args without rgb hash" do
14
- expect(RgbConverter.matches?(h: 225, s: 73, l: 57)).to be_false
14
+ expect(RgbConverter.matches?(h: 225, s: 73, l: 57)).to be false
15
15
  end
16
16
 
17
17
  it "should not match a string" do
18
- expect(RgbConverter.matches?("#ffffff")).to be_false
18
+ expect(RgbConverter.matches?("#ffffff")).to be false
19
19
  end
20
20
  end
21
21
 
@@ -38,4 +38,4 @@ describe RgbConverter do
38
38
  expect(conv.rgba).to eq rgba
39
39
  end
40
40
  end
41
- end
41
+ end
@@ -3,15 +3,15 @@ require 'spec_helper'
3
3
  describe RgbStringConverter do
4
4
  describe ".matches?" do
5
5
  it "should match args with rgb string" do
6
- expect(RgbStringConverter.matches?("rgb(51, 102, 204)")).to be_true
6
+ expect(RgbStringConverter.matches?("rgb(51, 102, 204)")).to be true
7
7
  end
8
8
 
9
9
  it "should match args with rgba string" do
10
- expect(RgbStringConverter.matches?("rgba(51, 102, 204, 0.2)")).to be_true
10
+ expect(RgbStringConverter.matches?("rgba(51, 102, 204, 0.2)")).to be true
11
11
  end
12
12
 
13
13
  it "should not match args without rgb string" do
14
- expect(RgbStringConverter.matches?(r: 51, g: 102, b: 204)).to be_false
14
+ expect(RgbStringConverter.matches?(r: 51, g: 102, b: 204)).to be false
15
15
  end
16
16
  end
17
17
 
@@ -42,4 +42,4 @@ describe RgbStringConverter do
42
42
  }.to raise_error(InvalidColorError)
43
43
  end
44
44
  end
45
- end
45
+ end
metadata CHANGED
@@ -1,94 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_conversion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Derek DeVries
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-17 00:00:00.000000000 Z
11
+ date: 2024-07-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '2.9'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '2.9'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: guard
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '1.7'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '1.7'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: guard-rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
61
  version: '2.5'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
68
  version: '2.5'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rb-fsevent
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ~>
73
+ - - "~>"
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0.9'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ~>
80
+ - - "~>"
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0.9'
94
83
  description: Convert colors to hex/rgb/hsv
@@ -98,7 +87,7 @@ executables: []
98
87
  extensions: []
99
88
  extra_rdoc_files: []
100
89
  files:
101
- - .gitignore
90
+ - ".gitignore"
102
91
  - Gemfile
103
92
  - Guardfile
104
93
  - LICENSE.txt
@@ -135,27 +124,25 @@ files:
135
124
  homepage: https://github.com/devrieda/color_conversion
136
125
  licenses:
137
126
  - MIT
138
- post_install_message:
127
+ metadata: {}
128
+ post_install_message:
139
129
  rdoc_options: []
140
130
  require_paths:
141
131
  - lib
142
132
  required_ruby_version: !ruby/object:Gem::Requirement
143
- none: false
144
133
  requirements:
145
- - - ! '>='
134
+ - - ">="
146
135
  - !ruby/object:Gem::Version
147
136
  version: 1.9.3
148
137
  required_rubygems_version: !ruby/object:Gem::Requirement
149
- none: false
150
138
  requirements:
151
- - - ! '>='
139
+ - - ">="
152
140
  - !ruby/object:Gem::Version
153
141
  version: '0'
154
142
  requirements: []
155
- rubyforge_project:
156
- rubygems_version: 1.8.25
157
- signing_key:
158
- specification_version: 3
143
+ rubygems_version: 3.3.7
144
+ signing_key:
145
+ specification_version: 4
159
146
  summary: Convert colors to hex/rgb/hsv
160
147
  test_files:
161
148
  - spec/color_converter_spec.rb
@@ -171,4 +158,3 @@ test_files:
171
158
  - spec/converters/rgb_string_converter_spec.rb
172
159
  - spec/spec_helper.rb
173
160
  - spec/version_spec.rb
174
- has_rdoc: