color-generator 0.0.3 → 0.0.4
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 +7 -0
- data/.travis.yml +4 -0
- data/README.md +3 -1
- data/color-generator.gemspec +3 -2
- data/lib/color-generator.rb +7 -2
- data/lib/color-generator/version.rb +2 -2
- data/spec/color-generator_spec.rb +30 -0
- data/spec/spec_helper.rb +7 -0
- metadata +30 -18
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2c0e53071b047cf14532a3dc3a802a8b0cef33df
|
4
|
+
data.tar.gz: 2644ae9c704f124e03ac54732a87854db0e05e51
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 948ca7652d941678e16437e155e4a63f3e4a45579887e11f08d1b9dbff2888109b987bd614ff17c84e040d2b3ff9e9fa0c18f059946f34501335907f100aa870
|
7
|
+
data.tar.gz: 18608f5f06374de49d3749684f0905d218060df81eb7c4cf66d5efa927f0db677a21837d0f47ba84d5751229e4f12c5878cb0177c89a17dffc567ed3a39918ab
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# Ruby Color Generator
|
2
2
|
|
3
|
+
[](http://travis-ci.org/opennorth/color-generator)
|
3
4
|
[](https://gemnasium.com/opennorth/color-generator)
|
4
|
-
[](https://coveralls.io/r/opennorth/color-generator)
|
6
|
+
[](https://codeclimate.com/github/opennorth/color-generator)
|
5
7
|
|
6
8
|
This gem randomly generates very distinct colors with consistent lightness and saturation.
|
7
9
|
|
data/color-generator.gemspec
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require "color-generator/version"
|
2
|
+
require File.expand_path('../lib/color-generator/version', __FILE__)
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
6
5
|
s.name = "color-generator"
|
@@ -10,6 +9,7 @@ Gem::Specification.new do |s|
|
|
10
9
|
s.email = ["info@opennorth.ca"]
|
11
10
|
s.homepage = "http://github.com/opennorth/color-generator"
|
12
11
|
s.summary = %q{Randomly generate distinct colors with consistent lightness and saturation}
|
12
|
+
s.license = 'MIT'
|
13
13
|
|
14
14
|
s.files = `git ls-files`.split("\n")
|
15
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -18,4 +18,5 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.add_development_dependency('rspec', '~> 2.10')
|
20
20
|
s.add_development_dependency('rake')
|
21
|
+
s.add_development_dependency('coveralls')
|
21
22
|
end
|
data/lib/color-generator.rb
CHANGED
@@ -12,9 +12,14 @@ class ColorGenerator
|
|
12
12
|
# @option opts [Float,Integer] :value value in the interval [0, 1], sets the
|
13
13
|
# color representation to HSV
|
14
14
|
# @option opts [Integer] :seed seed for the pseudorandom number generator
|
15
|
+
# @option opts [Float,Integer] :hue hue to use as the start in the interval [0, 1]
|
15
16
|
def initialize(opts = {})
|
16
|
-
|
17
|
-
|
17
|
+
if opts.key?(:hue)
|
18
|
+
@hue = opts[:hue]
|
19
|
+
else
|
20
|
+
srand(opts[:seed]) if opts.key?(:seed)
|
21
|
+
@hue = rand
|
22
|
+
end
|
18
23
|
@saturation = opts[:saturation].to_f
|
19
24
|
if opts.has_key? :lightness
|
20
25
|
@mode = :HSL
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
class ColorGenerator
|
2
|
+
VERSION = "0.0.4"
|
3
3
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe ColorGenerator do
|
4
|
+
it 'should accept a seed for the pseudorandom number generator' do
|
5
|
+
ColorGenerator.new(:saturation => 0.3, :value => 1.0, :seed => 1).create_hex.should == 'ffc3b3'
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should generate a random color as a hex triplet using the HSL color representation' do
|
9
|
+
ColorGenerator.new(:saturation => 0.3, :lightness => 0.75).create_hex.should match(/\A[0-9a-f]{6}\z/)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should generate a random color as a hex triplet using the HSV color representation' do
|
13
|
+
ColorGenerator.new(:saturation => 0.3, :value => 1.0).create_hex.should match(/\A[0-9a-f]{6}\z/)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should generate a random color as a decimal triplet' do
|
17
|
+
values = ColorGenerator.new(:saturation => 0.3, :value => 1.0).create_rgb
|
18
|
+
values.should be_an(Array)
|
19
|
+
values.each do |value|
|
20
|
+
value.should >= 0
|
21
|
+
value.should <= 255
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should use the provided hue' do
|
26
|
+
generator = ColorGenerator.new(:saturation => 0.3, :value => 1.0, :hue => 0.5)
|
27
|
+
generator.create_hex.should == 'ffe9b3'
|
28
|
+
generator.hue.should == 0.1180339887498949
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: color-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Open North
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-09-16 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
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
|
@@ -30,17 +27,29 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coveralls
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
44
53
|
- !ruby/object:Gem::Version
|
45
54
|
version: '0'
|
46
55
|
description:
|
@@ -61,29 +70,32 @@ files:
|
|
61
70
|
- color-generator.gemspec
|
62
71
|
- lib/color-generator.rb
|
63
72
|
- lib/color-generator/version.rb
|
73
|
+
- spec/color-generator_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
64
75
|
homepage: http://github.com/opennorth/color-generator
|
65
|
-
licenses:
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
66
79
|
post_install_message:
|
67
80
|
rdoc_options: []
|
68
81
|
require_paths:
|
69
82
|
- lib
|
70
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
84
|
requirements:
|
73
|
-
- -
|
85
|
+
- - '>='
|
74
86
|
- !ruby/object:Gem::Version
|
75
87
|
version: '0'
|
76
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
89
|
requirements:
|
79
|
-
- -
|
90
|
+
- - '>='
|
80
91
|
- !ruby/object:Gem::Version
|
81
92
|
version: '0'
|
82
93
|
requirements: []
|
83
94
|
rubyforge_project:
|
84
|
-
rubygems_version:
|
95
|
+
rubygems_version: 2.0.8
|
85
96
|
signing_key:
|
86
|
-
specification_version:
|
97
|
+
specification_version: 4
|
87
98
|
summary: Randomly generate distinct colors with consistent lightness and saturation
|
88
|
-
test_files:
|
89
|
-
|
99
|
+
test_files:
|
100
|
+
- spec/color-generator_spec.rb
|
101
|
+
- spec/spec_helper.rb
|