colver 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -14,8 +14,8 @@ require 'jeweler'
14
14
  Jeweler::Tasks.new do |gem|
15
15
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
16
16
  gem.name = "colver"
17
- gem.summary = %Q{Simple gem for playing with colors}
18
- gem.description = %Q{Simple gem for playing with colors}
17
+ gem.summary = %Q{A simple gem for playing with colors.}
18
+ gem.description = %Q{A simple gem for playing with colors.}
19
19
  gem.email = "ravicious@gmail.com"
20
20
  gem.homepage = "http://github.com/ravicious/colver"
21
21
  gem.authors = ["Rafał Cieślak"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/colver.gemspec ADDED
@@ -0,0 +1,80 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{colver}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Rafał Cieślak"]
12
+ s.date = %q{2010-11-14}
13
+ s.description = %q{A simple gem for playing with colors.}
14
+ s.email = %q{ravicious@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "colver.gemspec",
29
+ "lib/colver.rb",
30
+ "lib/colver/color.rb",
31
+ "lib/colver/conversions.rb",
32
+ "spec/color_spec.rb",
33
+ "spec/conversions_spec.rb",
34
+ "spec/spec_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/ravicious/colver}
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{A simple gem for playing with colors.}
40
+ s.test_files = [
41
+ "spec/color_spec.rb",
42
+ "spec/conversions_spec.rb",
43
+ "spec/spec_helper.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<rspec>, ["~> 2.0.0"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.0.pre5"])
54
+ s.add_development_dependency(%q<simplecov>, ["~> 0.3.5"])
55
+ s.add_development_dependency(%q<rspec>, ["~> 2.0.0"])
56
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.0.pre5"])
58
+ s.add_development_dependency(%q<simplecov>, ["~> 0.3.5"])
59
+ else
60
+ s.add_dependency(%q<rspec>, ["~> 2.0.0"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre5"])
63
+ s.add_dependency(%q<simplecov>, ["~> 0.3.5"])
64
+ s.add_dependency(%q<rspec>, ["~> 2.0.0"])
65
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
+ s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre5"])
67
+ s.add_dependency(%q<simplecov>, ["~> 0.3.5"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<rspec>, ["~> 2.0.0"])
71
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
72
+ s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre5"])
73
+ s.add_dependency(%q<simplecov>, ["~> 0.3.5"])
74
+ s.add_dependency(%q<rspec>, ["~> 2.0.0"])
75
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
76
+ s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre5"])
77
+ s.add_dependency(%q<simplecov>, ["~> 0.3.5"])
78
+ end
79
+ end
80
+
data/lib/colver/color.rb CHANGED
@@ -6,9 +6,10 @@ class Color
6
6
  alias :to_s :hex
7
7
 
8
8
  def initialize(color)
9
- if color.class == Array
9
+ case color
10
+ when Array
10
11
  from_array color
11
- elsif color.class == String
12
+ when String
12
13
  from_string color
13
14
  else
14
15
  raise ArgumentError, "Color#new argument must be an array or a string!"
@@ -20,6 +21,11 @@ class Color
20
21
  end
21
22
  alias :to_a :rgb
22
23
 
24
+ def eql?(other_color)
25
+ self.class.equal?(other_color.class) && hex == other_color.hex
26
+ end
27
+ alias :== :eql?
28
+
23
29
  def inspect
24
30
  "#<Color: hex: #{hex}, rgb: #{rgb}>"
25
31
  end
@@ -0,0 +1,17 @@
1
+ class String
2
+ def to_color
3
+ Color.new(self)
4
+ end
5
+ end
6
+
7
+ class Array
8
+ def to_color
9
+ Color.new(self)
10
+ end
11
+ end
12
+
13
+ class Integer
14
+ def to_color
15
+ Color.new(to_s)
16
+ end
17
+ end
data/lib/colver.rb CHANGED
@@ -1 +1,2 @@
1
1
  require_relative "colver/color"
2
+ require_relative "colver/conversions"
data/spec/color_spec.rb CHANGED
@@ -10,14 +10,14 @@ describe Color do
10
10
 
11
11
  describe 'instance with an array' do
12
12
  context 'with valid RGB values' do
13
- subject { Color.new([55, 3, 169]) }
13
+ subject { described_class.new([55, 3, 169]) }
14
14
 
15
15
  its(:hex) { should == "3703a9" }
16
16
  its(:rgb) { should == [55, 3, 169] }
17
17
  end
18
18
 
19
19
  context 'with low RGB values' do
20
- subject { Color.new([1, 2, 3]) }
20
+ subject { described_class.new([1, 2, 3]) }
21
21
 
22
22
  its(:hex) { should == "010203" }
23
23
  its(:rgb) { should == [1, 2, 3] }
@@ -31,7 +31,7 @@ describe Color do
31
31
 
32
32
  describe 'instance with an string' do
33
33
  context 'which is a word (for example "ravicious")' do
34
- subject { Color.new 'ravicious' }
34
+ subject { described_class.new 'ravicious' }
35
35
 
36
36
  its(:hex) { should == "fd3f3a" }
37
37
  its(:rgb) { should == [253, 63, 58] }
@@ -39,17 +39,17 @@ describe Color do
39
39
 
40
40
  context 'which is already a hex value' do
41
41
  context 'with 6 chars' do
42
- subject { Color.new '1b4fcd' }
42
+ subject { described_class.new '1b4fcd' }
43
43
 
44
44
  its(:hex) { should == '1b4fcd' }
45
45
  its(:rgb) { should == [27, 79, 205] }
46
46
  end
47
47
 
48
48
  context 'with less than 6 chars' do
49
- subject { Color.new '1b' }
49
+ subject { described_class.new '1b' }
50
50
 
51
51
  describe "hex" do
52
- before { @hex = Color.new('1b').hex }
52
+ before { @hex = described_class.new('1b').hex }
53
53
 
54
54
  it "should get longer" do
55
55
  @hex.should == '1b1b1b'
@@ -64,13 +64,18 @@ describe Color do
64
64
  end
65
65
 
66
66
  describe "valid instance" do
67
- before { @color = Color.new([234, 71, 63]) }
67
+ before { @color = described_class.new([234, 71, 63]) }
68
68
 
69
69
  it "should invert itself to the other color" do
70
70
  @color.invert.should be_instance_of Color
71
71
  @color.invert.rgb.should == [21, 184, 192]
72
72
  end
73
73
 
74
+ it "should be equal to the other color instance with the same values" do
75
+ other_color = described_class.new('ea473f')
76
+ @color.should == other_color
77
+ end
78
+
74
79
  describe "#inspect" do
75
80
  it "should respond with human-readable representation of a color" do
76
81
  @color.inspect.should == "#<Color: hex: ea473f, rgb: [234, 71, 63]>"
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ describe String do
5
+ describe "#to_color" do
6
+ it "should convert itself to a color" do
7
+ 'test'.to_color.should == Color.new('test')
8
+ '01'.to_color.should == Color.new('01')
9
+ end
10
+ end
11
+ end
12
+
13
+ describe Array do
14
+ describe "#to_color" do
15
+ it "should convert itself to a color" do
16
+ [123, 255, 6].to_color.should == Color.new([123, 255, 6])
17
+ [3, 25, 62].to_color.should == Color.new('03193e')
18
+ end
19
+ end
20
+ end
21
+
22
+ describe Integer do
23
+ describe "#to_color" do
24
+ it "should convert itself to a color" do
25
+ 1.to_color.should == Color.new('1')
26
+ 547301.to_color.should == Color.new('547301')
27
+ end
28
+ end
29
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'simplecov'
2
- SimpleCov.start
2
+ SimpleCov.start do
3
+ add_filter '/spec/'
4
+ end
3
5
 
4
6
  require 'colver'
5
7
  require 'rspec'
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Rafa\xC5\x82 Cie\xC5\x9Blak"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-13 00:00:00 +01:00
17
+ date: 2010-11-14 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -139,7 +139,7 @@ dependencies:
139
139
  type: :development
140
140
  prerelease: false
141
141
  version_requirements: *id008
142
- description: Simple gem for playing with colors
142
+ description: A simple gem for playing with colors.
143
143
  email: ravicious@gmail.com
144
144
  executables: []
145
145
 
@@ -157,9 +157,12 @@ files:
157
157
  - README.rdoc
158
158
  - Rakefile
159
159
  - VERSION
160
+ - colver.gemspec
160
161
  - lib/colver.rb
161
162
  - lib/colver/color.rb
163
+ - lib/colver/conversions.rb
162
164
  - spec/color_spec.rb
165
+ - spec/conversions_spec.rb
163
166
  - spec/spec_helper.rb
164
167
  has_rdoc: true
165
168
  homepage: http://github.com/ravicious/colver
@@ -175,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
178
  requirements:
176
179
  - - ">="
177
180
  - !ruby/object:Gem::Version
178
- hash: 1034222001
181
+ hash: 695985747
179
182
  segments:
180
183
  - 0
181
184
  version: "0"
@@ -193,7 +196,8 @@ rubyforge_project:
193
196
  rubygems_version: 1.3.7
194
197
  signing_key:
195
198
  specification_version: 3
196
- summary: Simple gem for playing with colors
199
+ summary: A simple gem for playing with colors.
197
200
  test_files:
198
201
  - spec/color_spec.rb
202
+ - spec/conversions_spec.rb
199
203
  - spec/spec_helper.rb