color-converter 0.0.1 → 1.0.0

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: 21661f8d4684b788378faf7e5294fa9ac46f22c5
4
- data.tar.gz: 18a2c8cc08696a3568c7c8b1680b8b2dc32718a5
3
+ metadata.gz: 93ca73eb327003cd451e0b28913b6b291041544c
4
+ data.tar.gz: a0ba32573c471494bf9bad0c94701fb531aa1aaf
5
5
  SHA512:
6
- metadata.gz: 7e46fd6cc51a8b87c3ce20e9507f288c46f2d5809f382c475b5d7e482c8bc5919e236e82a8405576a27a208e3971011ebdc394475625f999d9b48916c449dd61
7
- data.tar.gz: 0bc3b5d9ea124765a63aefbb27aa1e61a0be5f65cd90a8808c5350b242667f929e4c0bd4e8108a13d44fb7f5fbf1e47a398fff59be0998a7018b673abf6b08a7
6
+ metadata.gz: 21fd054616384a69070329f1cef03664bcc5941b59742dc81e81010a14058528febf6172a01ec7b594a8ebf0c460e8102705488db1204bb2e02132c8f92e9891
7
+ data.tar.gz: d1bd50de0146e73a1ab96e6d374cbd345e863ed00b3d0c13ae880bbdb99f5253680bb1faec4e0e9d645c39c2351c0e3840308d462068fce5532b1f5092d86663
@@ -4,4 +4,4 @@ rvm:
4
4
  - 2.0.0
5
5
  branches:
6
6
  only:
7
- - master
7
+ - master
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # ColorConverter
2
+ [![Gem Version](https://badge.fury.io/rb/color-converter.png)](http://badge.fury.io/rb/color-converter)
3
+ [![Build Status](https://travis-ci.org/dkan/color-converter.png?branch=master)](https://travis-ci.org/dkan/color-converter)
4
+ [![Dependency Status](https://gemnasium.com/dkan/color-converter.png)](https://gemnasium.com/dkan/color-converter)
5
+ [![Coverage Status](https://coveralls.io/repos/dkan/color-converter/badge.png)](https://coveralls.io/r/dkan/color-converter)
2
6
 
3
7
  ColorConverter is a simple way to convert between hexcolor, RGB, and CMYK values.
4
8
 
@@ -12,24 +16,20 @@ And then execute:
12
16
 
13
17
  $ bundle install
14
18
 
15
- ## Usage
16
-
17
- Convert to hexcolor example:
19
+ ## Usage:
18
20
 
21
+ require 'color_converter'
22
+
19
23
  # Returns a hexcolor code string
20
24
  # e.g. "#FFFFFF"
21
25
  ColorConverter.hex(255, 255, 255)
22
26
  ColorConverter.hex(0, 0, 0, 0)
23
-
24
- Convert to RGB example:
25
-
27
+
26
28
  # Returns an array of color values
27
29
  # e.g. [r, g, b]
28
30
  ColorConverter.rgb('#FFFFFF')
29
31
  ColorConverter.rgb(0, 0, 0, 0)
30
-
31
- Convert to CMYK example:
32
-
32
+
33
33
  # Returns an array of color values
34
34
  # e.g. [c, m, y, k]
35
35
  ColorConverter.cmyk('#000000')
@@ -1,6 +1,7 @@
1
1
  require "color_converter/version"
2
2
 
3
3
  module ColorConverter
4
+ HEX = "0123456789ABCDEF".freeze
4
5
 
5
6
  # Takes RGB or CMYK values as parameters and returns hexcolor code in
6
7
  # a string. Raises errors for incorrect inputs.
@@ -16,13 +17,13 @@ module ColorConverter
16
17
 
17
18
  return values[0] if values.count == 1
18
19
 
19
- # Raise error if values aren't Fixnums.
20
- values.each { |v| raise "Expecting Fixnum." unless v.class == Fixnum }
20
+ # Raise error if values aren't Integers.
21
+ ensure_all_integers! values
21
22
 
22
23
  hex_array = values
23
- hex_array = rgb(values[0], values[1], values[2], values[3]) if values.count == 4
24
+ hex_array = rgb(*values) if values.count == 4
24
25
  "#" + hex_array.map do |v|
25
- "0123456789ABCDEF"[(v-v%16)/16] + "0123456789ABCDEF"[v%16]
26
+ HEX[(v-v%16)/16] + HEX[v%16]
26
27
  end.join
27
28
  end
28
29
 
@@ -41,11 +42,11 @@ module ColorConverter
41
42
  return values if values.count == 3
42
43
 
43
44
  if values.count == 1
44
- hex_to_rgb(values[0])
45
+ hex_to_rgb(*values)
45
46
  elsif values.count == 4
46
- # Raise error if values aren't Fixnums.
47
- values.each { |v| raise "Expecting Fixnum." unless v.class == Fixnum }
48
- cmyk_to_rgb(values[0], values[1], values[2], values[3])
47
+ # Raise error if values aren't Integers.
48
+ ensure_all_integers! values
49
+ cmyk_to_rgb(*values)
49
50
  end
50
51
  end
51
52
 
@@ -65,12 +66,11 @@ module ColorConverter
65
66
 
66
67
  # Set cmky_array to array of RGB values.
67
68
  cmyk_array = values
68
- cmyk_array = rgb(values[0]) if values.count == 1
69
+ cmyk_array = rgb(*values) if values.count == 1
69
70
 
70
- # Raise error if values aren't Fixnums
71
- cmyk_array.each { |v| raise "Expecting Fixnum." unless v.class == Fixnum }
72
-
73
- rgb_to_cmyk(cmyk_array[0], cmyk_array[1], cmyk_array[2])
71
+ # Raise error if values aren't Integers
72
+ ensure_all_integers! cmyk_array
73
+ rgb_to_cmyk(*cmyk_array)
74
74
  end
75
75
 
76
76
  # Returns RGB values in array from hexcolor code.
@@ -123,4 +123,9 @@ module ColorConverter
123
123
  def self.correct_values? (values)
124
124
  [1, 3, 4].include? values.count
125
125
  end
126
+
127
+ # Raise error if values are not Integers.
128
+ def self.ensure_all_integers! (values)
129
+ raise "Expecting Integers." unless values.all?(&:integer?)
130
+ end
126
131
  end
@@ -1,5 +1,5 @@
1
1
  module Color
2
2
  module Converter
3
- VERSION = "0.0.1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -2,70 +2,70 @@ require 'spec_helper'
2
2
 
3
3
  describe ColorConverter do
4
4
  context "#hex" do
5
- it "should convert RGB to hexcolor" do
5
+ it "converts RGB to hexcolor" do
6
6
  ColorConverter.hex(0, 0, 0).should eq "#000000"
7
7
  ColorConverter.hex(210, 105, 30).should eq "#D2691E"
8
8
  end
9
9
 
10
- it "should convert CMYK to hexcolor" do
10
+ it "converts CMYK to hexcolor" do
11
11
  ColorConverter.hex(0, 50, 86, 18).should eq "#D2691E"
12
12
  end
13
13
 
14
- it "should return parameter if 1 value is entered" do
14
+ it "returns parameter if 1 value is entered" do
15
15
  ColorConverter.hex("#D2691E").should eq "#D2691E"
16
16
  end
17
17
 
18
- it "should raise error if incorrect number of values is entered" do
18
+ it "raises error if incorrect number of values is entered" do
19
19
  expect { ColorConverter.hex(0, 0, 0, 0, 0) }.to raise_error
20
20
  end
21
21
 
22
- it "should expect proper values" do
22
+ it "expects proper values" do
23
23
  expect { ColorConverter.hex("hello", "world", "foobar", "baz") }.to raise_error
24
24
  expect { ColorConverter.hex("hello", "world", "foobar") }.to raise_error
25
25
  end
26
26
  end
27
27
 
28
28
  context "#rgb" do
29
- it "should convert hexcolor to RGB" do
29
+ it "converts hexcolor to RGB" do
30
30
  ColorConverter.rgb("#D2691E").should eq [210, 105, 30]
31
31
  end
32
32
 
33
- it "should convert CMYK to RGB" do
33
+ it "converts CMYK to RGB" do
34
34
  ColorConverter.rgb(0, 50, 86, 18).should eq [210, 105, 30]
35
35
  end
36
36
 
37
- it "should return parameter if 3 values are entered" do
37
+ it "returns parameter if 3 values are entered" do
38
38
  ColorConverter.rgb(210, 105, 30).should eq [210, 105, 30]
39
39
  end
40
40
 
41
- it "should raise error if incorrect number of values is entered" do
41
+ it "raises error if incorrect number of values is entered" do
42
42
  expect { ColorConverter.rgb(0, 0) }.to raise_error
43
43
  end
44
44
 
45
- it "should expect proper values" do
45
+ it "expects proper values" do
46
46
  expect { ColorConverter.rgb("hello", "world", "foobar", "baz") }.to raise_error
47
47
  expect { ColorConverter.rgb("hello") }.to raise_error
48
48
  end
49
49
  end
50
50
 
51
51
  context "#cmyk" do
52
- it "should convert hexcolor to CMYK" do
52
+ it "converts hexcolor to CMYK" do
53
53
  ColorConverter.cmyk("#D2691E").should eq [0, 50, 86, 18]
54
54
  end
55
55
 
56
- it "should convert RGB to CMYK" do
56
+ it "converts RGB to CMYK" do
57
57
  ColorConverter.cmyk(210, 105, 30).should eq [0, 50, 86, 18]
58
58
  end
59
59
 
60
- it "should return parameter if 4 values are entered" do
60
+ it "returns parameter if 4 values are entered" do
61
61
  ColorConverter.cmyk(0, 50, 86, 18).should eq [0, 50, 86, 18]
62
62
  end
63
63
 
64
- it "should raise error if incorrect number of values is entered" do
64
+ it "raises error if incorrect number of values is entered" do
65
65
  expect { ColorConverter.cmyk(0, 0, 0, 0, 0) }.to raise_error
66
66
  end
67
67
 
68
- it "should expect proper values" do
68
+ it "expects proper values" do
69
69
  expect { ColorConverter.cmyk("hello", "world", "foobar") }.to raise_error
70
70
  expect { ColorConverter.cmyk("hello") }.to raise_error
71
71
  end
@@ -4,6 +4,11 @@ require 'bundler/setup'
4
4
 
5
5
  require 'simplecov'
6
6
  require 'coveralls'
7
+
8
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
9
+ SimpleCov::Formatter::HTMLFormatter,
10
+ Coveralls::SimpleCov::Formatter
11
+ ]
7
12
  SimpleCov.start
8
13
 
9
14
  require 'rack/test'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color-converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Kan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-16 00:00:00.000000000 Z
11
+ date: 2013-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler