colorable 0.0.7 → 0.0.8
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/lib/colorable/colorset.rb +7 -17
- data/lib/colorable/version.rb +1 -1
- data/spec/colorset_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd1ee00539ef3544f0938729f93a1abc32c3b3ec
|
4
|
+
data.tar.gz: 72879c844b5456ad6908cf0875cc5468f553b0ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a04a172d115e8c82c5f0d6746bebebd90670e74ac8a7a97bf8369c961a37de9e2825ef7ba6f57199862ef0253910af6d79d20ff20ef7bdc8ed925c7296d2694a
|
7
|
+
data.tar.gz: fe15f0a313eea761fbd741398159dad8d8aaa26d4f56f74b9ff1ff45a48cfaa571537578b4ccb95db1f02a88919b10ab91ea52ef8f10a3f79e8d4f25eb83a6a2
|
data/lib/colorable/colorset.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
1
3
|
module Colorable
|
2
4
|
class Colorset
|
3
5
|
include Enumerable
|
6
|
+
extend Forwardable
|
4
7
|
|
5
8
|
def initialize(colorset=nil)
|
6
9
|
@pos = 0
|
@@ -8,6 +11,8 @@ module Colorable
|
|
8
11
|
colorset || COLORNAMES.map { |name, rgb| Colorable::Color.new(name) }
|
9
12
|
end
|
10
13
|
|
14
|
+
def_delegators :@colorset, :size, :first, :last, :to_a
|
15
|
+
|
11
16
|
# +Colorset[:order]+ create a ordered colorset by passing a order key.
|
12
17
|
def self.[](order, dir=:+, colorset=nil)
|
13
18
|
rgb = [:red, :green, :blue]
|
@@ -36,10 +41,6 @@ module Colorable
|
|
36
41
|
@colorset.each(&blk)
|
37
42
|
end
|
38
43
|
|
39
|
-
def size
|
40
|
-
@colorset.size
|
41
|
-
end
|
42
|
-
|
43
44
|
def at(pos=0)
|
44
45
|
@colorset[(@pos+pos)%size]
|
45
46
|
end
|
@@ -59,16 +60,9 @@ module Colorable
|
|
59
60
|
at
|
60
61
|
end
|
61
62
|
|
62
|
-
def last(n=1)
|
63
|
-
@colorset.last(n)
|
64
|
-
end
|
65
|
-
|
66
|
-
def first(n=1)
|
67
|
-
@colorset.first(n)
|
68
|
-
end
|
69
|
-
|
70
63
|
def find_index(color)
|
71
|
-
@colorset.find_index { |c| c == color }
|
64
|
+
idx = @colorset.find_index { |c| c == color }
|
65
|
+
(@pos+idx)%size if idx
|
72
66
|
end
|
73
67
|
|
74
68
|
def sort_by(&blk)
|
@@ -79,10 +73,6 @@ module Colorable
|
|
79
73
|
self.class.new @colorset.reverse
|
80
74
|
end
|
81
75
|
|
82
|
-
def to_a
|
83
|
-
@colorset
|
84
|
-
end
|
85
|
-
|
86
76
|
def to_s
|
87
77
|
"#<%s %d/%d pos='%s:%s'>" % [:Colorset, @pos, size, at.name, at]
|
88
78
|
end
|
data/lib/colorable/version.rb
CHANGED
data/spec/colorset_spec.rb
CHANGED
@@ -13,13 +13,13 @@ describe Colorable::Colorset do
|
|
13
13
|
context "when :rgb passed" do
|
14
14
|
before(:all) { @cs = colorset[:rgb] }
|
15
15
|
it { @cs.take(3).map(&:to_s).should eql ['rgb(0,0,0)', 'rgb(0,0,128)', 'rgb(0,0,139)'] }
|
16
|
-
it { @cs.last.
|
16
|
+
it { @cs.last.to_s.should eql 'rgb(255,255,255)' }
|
17
17
|
end
|
18
18
|
|
19
19
|
context "when :red" do
|
20
20
|
before(:all) { @cs = colorset[:red] }
|
21
21
|
it { @cs.take(3).map(&:to_s).should eql ['rgb(0,0,0)', 'rgb(0,0,128)', 'rgb(0,0,139)'] }
|
22
|
-
it { @cs.last.
|
22
|
+
it { @cs.last.to_s.should eql 'rgb(255,255,255)' }
|
23
23
|
end
|
24
24
|
|
25
25
|
context "when :green in descent order" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colorable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kyoendo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|