cpalette 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c81724f8b77e7868578b57539301575cda7c715b
4
- data.tar.gz: 2ae699cbd1b0573d9026dd9131164bb5eea78c35
3
+ metadata.gz: 34efed280ebbd1257990a1b2cfcb9ec64ae65cf8
4
+ data.tar.gz: f85f5b678de5acf6b8200921085a7a91c9a481fd
5
5
  SHA512:
6
- metadata.gz: 7aee40652bad9dc1a00f9f268fd47f769e27b80cc71c8cf31971fcf5c509d4f0d47c47ff525a81d88e0a8e8e0e769127e01fc1d0678002e077b0141c641f5857
7
- data.tar.gz: 5f7ef62eff03e9578f662466bed267a45760bed58c5605089c70cbf40af02e109b91b3d58400fb8cf54e9d420bbdba270d2aed78fa33bda33b12ceb0b60e19c5
6
+ metadata.gz: addb05641ca25fdf2b6d430432115476377de4069bd074ca82ef8bee401d3ab1210ecbab7981ccc35513797ee27826f2be631ce726d7502406eab967098902a7
7
+ data.tar.gz: 5b7276c8f0b3de2bcf5549cf56d1a48403962f0ce0c0817b1e9a89b44d9f9da493d7002580b646dc321b9cd44803d01f30a149365e4a3b1ce2d331b0dcaa98a7
data/Gemfile.lock CHANGED
@@ -1,12 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cpalette (0.0.2)
4
+ cpalette (0.0.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ coderay (1.1.0)
9
10
  diff-lcs (1.2.5)
11
+ docile (1.1.5)
12
+ method_source (0.8.2)
13
+ multi_json (1.10.1)
14
+ pry (0.10.1)
15
+ coderay (~> 1.1.0)
16
+ method_source (~> 0.8.1)
17
+ slop (~> 3.4)
10
18
  rake (10.3.2)
11
19
  rspec (3.0.0)
12
20
  rspec-core (~> 3.0.0)
@@ -20,6 +28,12 @@ GEM
20
28
  rspec-mocks (3.0.2)
21
29
  rspec-support (~> 3.0.0)
22
30
  rspec-support (3.0.2)
31
+ simplecov (0.9.0)
32
+ docile (~> 1.1.0)
33
+ multi_json
34
+ simplecov-html (~> 0.8.0)
35
+ simplecov-html (0.8.0)
36
+ slop (3.6.0)
23
37
 
24
38
  PLATFORMS
25
39
  ruby
@@ -27,5 +41,7 @@ PLATFORMS
27
41
  DEPENDENCIES
28
42
  bundler (~> 1.6)
29
43
  cpalette!
30
- rake
31
- rspec
44
+ pry (~> 0.10)
45
+ rake (~> 10)
46
+ rspec (~> 3.0)
47
+ simplecov (~> 0.9)
data/README.md CHANGED
@@ -1,8 +1,5 @@
1
1
  # Cpalette
2
2
 
3
- Cpalette
4
- ----------------------
5
-
6
3
  A simple color gem that returns you with a palette of colors which are web friendly and easy to use.
7
4
 
8
5
  ## Installation
@@ -21,22 +18,26 @@ Or install it yourself as:
21
18
 
22
19
  ## Usage
23
20
 
24
- Case 1:
21
+ _Case 1:_
22
+
23
+ Just pass in the number of colors you needs, returns you an array of 4 hashes with hsl, rgb and hex values for each color.
24
+
25
+ ```ruby
25
26
  colors_array = Cpalette.palette(4)
26
27
 
27
28
  => [{"hsl"=>"359,62%,46%", "rgb"=>"190,45,47", "hex"=>"#be2d2f"}, {"hsl"=>"89,62%,80%", "rgb"=>"205,236,172", "hex"=>"#cdecac"}, {"hsl"=>"269,80%,71%", "rgb"=>"179,122,240", "hex"=>"#b37af0"}, {"hsl"=>"179,69%,79%", "rgb"=>"165,238,237", "hex"=>"#a5eeed"}]
29
+ ```
28
30
 
29
- colors_array returns you with an array of 4 hashes with hsl, rgb and hex values for each color.
31
+ _Case 2:_
30
32
 
31
- Case 2:
32
- You can pass an option :hex => true, which would return you an array containing only Hex values of required number of colors.
33
+ You can pass an optional :hex => true, which return you an array containing only Hex values of required number of colors.
33
34
 
34
-
35
+ ```ruby
35
36
  colors_array = Cpalette.palette(4, {:hex => true})
36
37
 
37
38
  => ["#37e1de", "#a468e3", "#f0383b", "#a5e660"]
38
39
 
39
- Returned colors_array contains only hex values of 4 different colors.
40
+ ```
40
41
 
41
42
  ## Contributing
42
43
 
data/cpalette.gemspec CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency "rake", "~> 10"
23
+ spec.add_development_dependency "pry", "~> 0.10"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "simplecov", "~> 0.9"
24
26
  end
data/lib/cpalette.rb CHANGED
@@ -1,26 +1,13 @@
1
1
  require "cpalette/version"
2
2
 
3
3
  module Cpalette
4
- def get_hsl_values_decimal(color)
5
-
6
- end
7
- def get_color_codes_in_hex(h, s, l)
8
-
9
- end
10
- def self.hue2rgb(p,q,t)
11
- t = t + 1 if t < 0
12
- t = t -1 if t > 1
13
- if 6 * t < 1
14
- return p+(q-p)*6*t
15
- end
16
- if 2 * t < 1
17
- return q
18
- end
19
- if 3 * t < 2
20
- return p + (q - p) * ((2.0/3 - t) * 6)
21
- end
22
- return p
23
- end
4
+ # Given Hue, Saturation and Lightness values return RGB values to it.
5
+ # Function adopted from - http://easyrgb.com
6
+ # Assumes inputs: h, s, l are in the range of [0,1]
7
+ # Returns outputs: R, G, B valu in the range of [0,255]
8
+ # E.g.
9
+ # Inputs: h: 0.25, s: 0.89, l: 0.54
10
+ # Output: r: 141, g: 242, b: 33
24
11
  def self.get_color_codes_in_rgb(h, s, l)
25
12
  if s == 0
26
13
  r = g = b = l * 255
@@ -37,12 +24,41 @@ module Cpalette
37
24
  end
38
25
  return "#{r},#{g},#{b}"
39
26
  end
27
+
28
+ # Converts hue to rgb based on following conditions
29
+ def self.hue2rgb(p,q,t)
30
+ t = t + 1 if t < 0
31
+ t = t -1 if t > 1
32
+ if 6 * t < 1
33
+ return p+(q-p)*6*t
34
+ end
35
+ if 2 * t < 1
36
+ return q
37
+ end
38
+ if 3 * t < 2
39
+ return p + (q - p) * ((2.0/3 - t) * 6)
40
+ end
41
+ return p
42
+ end
43
+
44
+ # Converts RGB to HEX code values
45
+ # R, G, B are converted to string of base 16 and padded a 0 if length is less than 2
46
+ # Assumes input r, g, b in the range of [0, 255]
47
+ # Returns a HEX value
48
+ # E.g Input - r: 255, g:255, b:255 => #FFFFFF
49
+ #
40
50
  def self.rgb2hex(r, g, b)
41
51
  h1 = r.to_s(16).length == 2 ? r.to_s(16) : "0"+r.to_s(16)
42
52
  h2 = g.to_s(16).length == 2 ? g.to_s(16) : "0"+g.to_s(16)
43
53
  h3 = b.to_s(16).length == 2 ? b.to_s(16) : "0"+b.to_s(16)
44
54
  return "##{h1}#{h2}#{h3}"
45
55
  end
56
+
57
+ # Takes an input parameter of size (no of colors and options hash)
58
+ # Returns equivalent number of random colors with HSL, RGB, HEX codes
59
+ # Max possible values for Hue: 360, Saturation: 100, Lightness: 100
60
+ # Saturation and Lightness values tend to determine the extremes of a color
61
+ # Choosing a range of 60..90 tends to give optimum colors
46
62
  def self.palette(size, options = {})
47
63
  color_palette = []
48
64
  hue_array = []
@@ -53,7 +69,7 @@ module Cpalette
53
69
  hue_array.push(hue)
54
70
  hue = hue - step_size
55
71
  end
56
- hue_array.shuffle!
72
+ hue_array.shuffle! #Inplace
57
73
  hue_array.each do |hue|
58
74
  s = Random.new.rand(60..90)
59
75
  l = Random.new.rand(40..80)
@@ -64,6 +80,7 @@ module Cpalette
64
80
  color_codes["hex"] = rgb2hex(rgb[0].to_i, rgb[1].to_i, rgb[2].to_i)
65
81
  color_palette.push(color_codes) unless color_palette.include?(color_codes)
66
82
  end
83
+ # If only hex option is set by user
67
84
  if options[:hex] != nil
68
85
  if options[:hex] == true
69
86
  cpalette = []
@@ -73,6 +90,7 @@ module Cpalette
73
90
  color_palette = cpalette
74
91
  end
75
92
  end
93
+ # binding.pry
76
94
  return color_palette
77
95
  end
78
96
  end
@@ -1,3 +1,3 @@
1
1
  module Cpalette
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -1,7 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Cpalette' do
4
- xit 'gives all three types of color codes' do
5
-
3
+ describe Cpalette do
4
+ describe "#get_color_codes_in_rgb" do
5
+ let(:output) {"117,240,240"}
6
+ it 'returns RGB values for given HSL values' do
7
+ expect(Cpalette.get_color_codes_in_rgb(0.5, 0.8, 0.7)).to eq(output)
8
+ end
9
+ it 'handles case when saturation is 0' do
10
+ expect(Cpalette.get_color_codes_in_rgb(0.5, 0, 1)).to eq("255,255,255")
11
+ end
12
+ end
13
+ describe "#rgb2hex" do
14
+ let(:output) {"#ffffff"}
15
+ it 'returns RGB values for given HSL values' do
16
+ expect(Cpalette.rgb2hex(255, 255, 255)).to eq(output)
17
+ end
18
+ end
19
+ describe "#palette" do
20
+ it 'gives all three types of color codes' do
21
+ expect(Cpalette.palette(4)).to be_truthy
22
+ end
23
+ it 'returns only hex values when options[:hex] is true' do
24
+ expect(Cpalette.palette(4, {:hex => true})).to be_truthy
25
+ end
6
26
  end
7
27
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,4 @@
1
- require 'cpalette'
1
+ require 'simplecov'
2
+ # Must be ahead of requiring core library to start the code coverage.
3
+ SimpleCov.start
4
+ require 'cpalette'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpalette
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - avinash-vllbh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-20 00:00:00.000000000 Z
11
+ date: 2014-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,30 +28,58 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '0'
54
+ version: '0.10'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ">="
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: '3.0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
53
81
  - !ruby/object:Gem::Version
54
- version: '0'
82
+ version: '0.9'
55
83
  description: A simple color gem that returns you with a palette of colors which are
56
84
  web friendly and easy to use.
57
85
  email: