colorable 0.2.0 → 0.2.1
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 +4 -4
- data/README.md +1 -1
- data/lib/colorable.rb +2 -2
- data/lib/colorable/color.rb +3 -4
- data/lib/colorable/color_space.rb +12 -11
- data/lib/colorable/version.rb +1 -1
- data/spec/color_space_spec.rb +11 -11
- data/spec/colorable_spec.rb +3 -3
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4a11c6f3fb1a54f8c2e393a5f055572dbd0887d
|
4
|
+
data.tar.gz: d9c5156517029fa6f26b51082da71f0f90d7ca14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d88df4e59bc8eddc1d255eacb7fda91d2015b4da13b23627914b92e94079b4090a3484350ffc72463521050c5866cf1d2131cbb236a3155a41dc61671fe1d3b0
|
7
|
+
data.tar.gz: c643c0df11f2a2105fac14f7741e5af307c4c4d6da31293141ac11f814d45ae3ea5a1a46c35e4d91ae9ce03296210ff2c6a55940995593ace0902eaedb0335b8
|
data/README.md
CHANGED
@@ -120,7 +120,7 @@ Color mode:
|
|
120
120
|
c + [15, -20, -74] # => #<Colorable::Color 'Moccasin<rgb(255,228,181)/hsb(39,29,100)/#FFE4B5>'>
|
121
121
|
c - 20 # => #<Colorable::Color '<rgb(220,228,235)/hsb(208,6,92)/#DCE4EB>'>
|
122
122
|
|
123
|
-
c.mode = :HSB
|
123
|
+
c.mode = :HSB
|
124
124
|
c.to_s # => "hsb(208,6,100)"
|
125
125
|
c.next # => #<Colorable::Color 'Slate Gray<rgb(112,128,144)/hsb(210,22,56)/#708090>'>
|
126
126
|
c + [152, 94, 0] # => #<Colorable::Color 'Red<rgb(255,0,0)/hsb(0,100,100)/#FF0000>'>
|
data/lib/colorable.rb
CHANGED
@@ -12,10 +12,10 @@ module Colorable
|
|
12
12
|
|
13
13
|
end
|
14
14
|
|
15
|
-
[String, Symbol, Array,
|
15
|
+
[String, Symbol, Array, Integer].each do |klass|
|
16
16
|
klass.class_eval do
|
17
17
|
define_method(:to_color) do
|
18
|
-
Colorable::Color.new (klass==
|
18
|
+
Colorable::Color.new (klass==Integer ? self.to_s(16) : self)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/colorable/color.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Colorable
|
2
2
|
class Color
|
3
|
-
class NameError < StandardError; end
|
4
3
|
include Comparable
|
5
4
|
|
6
5
|
# Create a Color object which has several representations of a color.
|
@@ -122,7 +121,7 @@ module Colorable
|
|
122
121
|
#
|
123
122
|
# +other+ can be:
|
124
123
|
# Color object: apply minimum compositing with its RGBs.
|
125
|
-
# Array of values or
|
124
|
+
# Array of values or Integer: addiction applies based on its color mode.
|
126
125
|
def +(other)
|
127
126
|
case other
|
128
127
|
when Color
|
@@ -136,7 +135,7 @@ module Colorable
|
|
136
135
|
#
|
137
136
|
# +other+ can be:
|
138
137
|
# Color object: apply maximum compositing with its RGBs.
|
139
|
-
# Array of values or
|
138
|
+
# Array of values or Integer: subtruction applies based on its color mode.
|
140
139
|
def -(other)
|
141
140
|
case other
|
142
141
|
when Color
|
@@ -227,4 +226,4 @@ module Colorable
|
|
227
226
|
self.class.new(rgb).tap { |c| c.mode = self.mode }
|
228
227
|
end
|
229
228
|
end
|
230
|
-
end
|
229
|
+
end
|
@@ -17,7 +17,7 @@ module Colorable
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def -(arg)
|
20
|
-
arg = arg.is_a?(
|
20
|
+
arg = arg.is_a?(Integer) ? -arg : arg.map(&:-@)
|
21
21
|
self + arg
|
22
22
|
end
|
23
23
|
|
@@ -55,7 +55,7 @@ module Colorable
|
|
55
55
|
# +other+ can be:
|
56
56
|
# RGB object: apply minimum compositing.
|
57
57
|
# Array of RGB values: each values added to each of RGBs.
|
58
|
-
#
|
58
|
+
# Integer: other number added to all of RGBs.
|
59
59
|
def +(other)
|
60
60
|
rgb =
|
61
61
|
case other
|
@@ -64,7 +64,7 @@ module Colorable
|
|
64
64
|
when Array
|
65
65
|
raise ArgumentError, "Invalid size of Array given" unless other.size==3
|
66
66
|
compound_by(other) { |a, b| (a + b) % 256 }
|
67
|
-
when
|
67
|
+
when Integer
|
68
68
|
compound_by([other] * 3) { |a, b| (a + b) % 256 }
|
69
69
|
else
|
70
70
|
raise ArgumentError, "Invalid argument given"
|
@@ -77,7 +77,7 @@ module Colorable
|
|
77
77
|
# +other+ can be:
|
78
78
|
# RGB object: apply maximum compositing.
|
79
79
|
# Array of RGB values: each values added to each of RGBs.
|
80
|
-
#
|
80
|
+
# Integer: other number added to all of RGBs.
|
81
81
|
def -(other)
|
82
82
|
case other
|
83
83
|
when RGB
|
@@ -133,6 +133,7 @@ module Colorable
|
|
133
133
|
class HSB < ColorSpace
|
134
134
|
attr_accessor :hsb, :h, :s, :b
|
135
135
|
def initialize(h=0,s=0,b=0)
|
136
|
+
h=0 if h==360
|
136
137
|
@h, @s, @b = @hsb = validate_hsb([h, s, b])
|
137
138
|
end
|
138
139
|
alias :hue :h
|
@@ -141,7 +142,7 @@ module Colorable
|
|
141
142
|
alias :to_a :hsb
|
142
143
|
undef :coerce
|
143
144
|
|
144
|
-
# Pass Array of [h, s, b] or a
|
145
|
+
# Pass Array of [h, s, b] or a Integer.
|
145
146
|
# Returns new HSB object with added HSB.
|
146
147
|
def +(arg)
|
147
148
|
arg =
|
@@ -232,12 +233,12 @@ module Colorable
|
|
232
233
|
def build_hex_with(op, arg)
|
233
234
|
_rgb =
|
234
235
|
case arg
|
235
|
-
when
|
236
|
+
when Integer
|
236
237
|
[arg] * 3
|
237
238
|
when String
|
238
239
|
hex2rgb(validate_hex arg)
|
239
240
|
else
|
240
|
-
raise ArgumentError, "Accept only a Hex string or a
|
241
|
+
raise ArgumentError, "Accept only a Hex string or a Integer"
|
241
242
|
end
|
242
243
|
rgb = hex2rgb(self.hex).zip(_rgb).map { |x, y| (x.send(op, y)) % 256 }
|
243
244
|
self.class.new rgb2hex(rgb)
|
@@ -267,13 +268,13 @@ module Colorable
|
|
267
268
|
end
|
268
269
|
|
269
270
|
def +(n)
|
270
|
-
raise ArgumentError, 'Only accept a
|
271
|
+
raise ArgumentError, 'Only accept a Integer' unless n.is_a?(Integer)
|
271
272
|
pos = COLORNAMES.find_index{|n,_| n==self.name} + n
|
272
273
|
self.class.new COLORNAMES.at(pos % COLORNAMES.size)[0]
|
273
274
|
end
|
274
275
|
|
275
276
|
def -(n)
|
276
|
-
raise ArgumentError, 'Only accept a
|
277
|
+
raise ArgumentError, 'Only accept a Integer' unless n.is_a?(Integer)
|
277
278
|
self + -n
|
278
279
|
end
|
279
280
|
|
@@ -300,6 +301,6 @@ module Colorable
|
|
300
301
|
} || begin
|
301
302
|
raise ArgumentError, "'#{name}' is not in X11 colorset."
|
302
303
|
end
|
303
|
-
end
|
304
|
+
end
|
304
305
|
end
|
305
|
-
end
|
306
|
+
end
|
data/lib/colorable/version.rb
CHANGED
data/spec/color_space_spec.rb
CHANGED
@@ -51,7 +51,7 @@ describe RGB do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
context "pass a
|
54
|
+
context "pass a Integer" do
|
55
55
|
before(:all) { @rgb = RGB.new(100, 100, 100) }
|
56
56
|
it { (@rgb + 50).rgb.should eql [150, 150, 150] }
|
57
57
|
it "not raise ArgumentError" do
|
@@ -59,7 +59,7 @@ describe RGB do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
context "coerce make
|
62
|
+
context "coerce make Integer#+ accept rgb object" do
|
63
63
|
it { (10 + RGB.new(100, 100, 100)).rgb.should eql [110, 110, 110] }
|
64
64
|
end
|
65
65
|
|
@@ -93,7 +93,7 @@ describe RGB do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
context "pass a
|
96
|
+
context "pass a Integer" do
|
97
97
|
before(:all) { @rgb = RGB.new(100, 100, 100) }
|
98
98
|
it { (@rgb - 50).rgb.should eql [50, 50, 50] }
|
99
99
|
it "not raise ArgumentError" do
|
@@ -270,13 +270,13 @@ describe NAME do
|
|
270
270
|
end
|
271
271
|
end
|
272
272
|
|
273
|
-
context "pass a
|
273
|
+
context "pass a Integer" do
|
274
274
|
before(:all) { @name = NAME.new(:alice_blue) }
|
275
275
|
it { (@name + 1).name.should eql 'Antique White' }
|
276
276
|
it { (@name + 2).name.should eql 'Aqua' }
|
277
277
|
end
|
278
278
|
|
279
|
-
context "coerce make
|
279
|
+
context "coerce make Integer#+ accept name object" do
|
280
280
|
it { (1 + NAME.new(:alice_blue)).to_s.should eql 'Antique White' }
|
281
281
|
end
|
282
282
|
end
|
@@ -288,13 +288,13 @@ describe NAME do
|
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
291
|
-
context "pass a
|
291
|
+
context "pass a Integer" do
|
292
292
|
before(:all) { @name = NAME.new(:alice_blue) }
|
293
293
|
it { (@name - 1).name.should eql 'Yellow Green' }
|
294
294
|
it { (@name - 2).name.should eql 'Yellow' }
|
295
295
|
end
|
296
296
|
|
297
|
-
context "coerce make
|
297
|
+
context "coerce make Integer#+ accept name object" do
|
298
298
|
it { (1 - NAME.new(:alice_blue)).to_s.should eql 'Yellow Green' }
|
299
299
|
end
|
300
300
|
end
|
@@ -361,7 +361,7 @@ describe HEX do
|
|
361
361
|
end
|
362
362
|
end
|
363
363
|
|
364
|
-
context "pass a
|
364
|
+
context "pass a Integer" do
|
365
365
|
before(:all) { @hex = HEX.new('#000000') }
|
366
366
|
it { (@hex + 255).hex.should eql '#FFFFFF' }
|
367
367
|
it "not raise ArgumentError" do
|
@@ -369,7 +369,7 @@ describe HEX do
|
|
369
369
|
end
|
370
370
|
end
|
371
371
|
|
372
|
-
context "coerce make
|
372
|
+
context "coerce make Integer#+ accept hex object" do
|
373
373
|
it { (255 + HEX.new('#000000')).hex.should eql '#FFFFFF' }
|
374
374
|
end
|
375
375
|
end
|
@@ -397,7 +397,7 @@ describe HEX do
|
|
397
397
|
end
|
398
398
|
end
|
399
399
|
|
400
|
-
context "pass a
|
400
|
+
context "pass a Integer" do
|
401
401
|
before(:all) { @hex = HEX.new('#FFFFFF') }
|
402
402
|
it { (@hex - 255).hex.should eql '#000000' }
|
403
403
|
it "not raise ArgumentError" do
|
@@ -405,7 +405,7 @@ describe HEX do
|
|
405
405
|
end
|
406
406
|
end
|
407
407
|
|
408
|
-
context "coerce make
|
408
|
+
context "coerce make Integer#+ accept hex object" do
|
409
409
|
it { (255 - HEX.new('#FFFFFF')).hex.should eql '#000000' }
|
410
410
|
end
|
411
411
|
end
|
data/spec/colorable_spec.rb
CHANGED
@@ -51,14 +51,14 @@ describe Colorable do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
describe "
|
55
|
-
context "apply a hex
|
54
|
+
describe "Integer#to_color" do
|
55
|
+
context "apply a hex Integer" do
|
56
56
|
subject { 0x32CD32.to_color }
|
57
57
|
it { should be_instance_of Colorable::Color }
|
58
58
|
its(:to_s) { should eql "#32CD32" }
|
59
59
|
end
|
60
60
|
|
61
|
-
context "apply a invalid
|
61
|
+
context "apply a invalid Integer" do
|
62
62
|
it "raise ArgumentError" do
|
63
63
|
expect { 323232.to_color }.to raise_error ArgumentError
|
64
64
|
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colorable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kyoendo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: A simple color handler which provide a conversion between colorname,
|
@@ -32,7 +32,7 @@ executables: []
|
|
32
32
|
extensions: []
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
|
-
- .gitignore
|
35
|
+
- ".gitignore"
|
36
36
|
- Gemfile
|
37
37
|
- LICENSE.txt
|
38
38
|
- README.md
|
@@ -60,17 +60,17 @@ require_paths:
|
|
60
60
|
- lib
|
61
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
62
|
requirements:
|
63
|
-
- -
|
63
|
+
- - ">="
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: 1.9.3
|
66
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- -
|
68
|
+
- - ">="
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
72
|
rubyforge_project:
|
73
|
-
rubygems_version: 2.
|
73
|
+
rubygems_version: 2.6.13
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
76
|
summary: A simple color handler which provide a conversion between colorname, RGB,
|