color_conversion 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f965f45721f6ef3f8f3817ba070dadac6404682594d0aabf77ab22ebd5d16208
4
- data.tar.gz: 8b7bdd47f4d7d38d7b18cc142c05909941995378fe2b746a2ae429d4ed7bd903
3
+ metadata.gz: 67ef203f22ffbece2c150be570dcd841c9ea476da8352afaa41b1ea1988ca7b9
4
+ data.tar.gz: 17f62d21d1073db851c7d0e732b32d1f3b36637ae27bbf781a3e869c58c65dad
5
5
  SHA512:
6
- metadata.gz: cf2631f1b3e29c3d499b0790f3b570523c3c1a67e1abad3f96690c47833388cf72f994953e550d6c567122b40a665a95d9576598dd510c5d89cc2e5fa1e37327
7
- data.tar.gz: dba487db8edf71d9895336eb603e3e42bdb77b1ade87a405f86e6a2d49ca8861ca0f8e2f6f4eac72dc8a27bafaead0809999255b9cb1f11d935528bd716c022c
6
+ metadata.gz: 2dbacd4819c95094cfc6a296b1503a8950b7fdf9a50b3eba26cbd3613a8b07d0c2e0f257db45e202d4081f90944e60f1045f0e8569dc6456c66475ab1e39313c
7
+ data.tar.gz: 98beb5c98f321f891af4f06d49bd6b629417a886894c2e1d803335daf6e960d3c17dc31190f4b1734e0d8cef8ceec399f63b613be4cbc2564719a6bf812e1c35
@@ -6,5 +6,11 @@ module ColorConversion
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
@@ -1,3 +1,3 @@
1
1
  module ColorConversion
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_conversion
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
  - Derek DeVries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-12 00:00:00.000000000 Z
11
+ date: 2024-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
- rubygems_version: 3.2.22
143
+ rubygems_version: 3.3.7
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: Convert colors to hex/rgb/hsv