rgb2hex 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -0
- data/Rakefile +8 -0
- data/test/test_rgb2hex.rb +91 -0
- metadata +27 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc4860c3e7f0fdf38d6a213e9f492c70c9780bad
|
4
|
+
data.tar.gz: 9287bec4eb239ac663b140d50655bc6fc2b86045
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcc60ea73e39b2685183209cb73d9ce58814e10d1b4fce753ba7c5c9d30f7fd529fb389096209e7c83cea793e8b05f2f1b3f77969b2f9daba9c5218408c4504d
|
7
|
+
data.tar.gz: 3201752c8b75e5a11f73d9f5df26529f689f634785b01a546df61f05611de78c486e29d30a233976172751ef63eff9ef43e4365a821e69ea8cff7cd7fdedea8e
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Day 1. Rgb2Hex
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rgb2hex.png)](http://badge.fury.io/rb/rgb2hex)
|
4
|
+
[![Build Status](https://travis-ci.org/zjjz/180-tools.png)](https://travis-ci.org/zjjz/180-tools)
|
5
|
+
|
6
|
+
|
7
|
+
`Rgb2Hex` is a ruby gem which lets you quickly convert RGB value of a color to its HEX value.
|
8
|
+
|
9
|
+
## Install
|
10
|
+
|
11
|
+
Gem is [hosted on RubyGems.org](https://rubygems.org/gems/rgb2hex). To install the gem enter the following command:
|
12
|
+
|
13
|
+
>> gem install rgb2hex
|
14
|
+
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
`Rgb2Hex` expects 3 integer values between 0 and 255 each separated by a space. It produces a HEX value prefixed with `#`. `Rgb2Hex` gem comes with a binary, which allows the gem to be used from the console.
|
19
|
+
|
20
|
+
>> rgb2hex 255 0 144 # magenta
|
21
|
+
=> #ff0090
|
data/Rakefile
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rgb2hex'
|
3
|
+
|
4
|
+
class Rgb2HexTest < Test::Unit::TestCase
|
5
|
+
def test_defaults_to_black
|
6
|
+
assert_equal "#000000",
|
7
|
+
Rgb2Hex.convert
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_converts_black
|
11
|
+
assert_equal "#000000",
|
12
|
+
Rgb2Hex.convert(0, 0, 0)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_converts_white
|
16
|
+
assert_equal "#ffffff",
|
17
|
+
Rgb2Hex.convert(255, 255, 255)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_converts_magenta
|
21
|
+
assert_equal "#ff0090",
|
22
|
+
Rgb2Hex.convert(255, 0, 144)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_converts_cyan
|
26
|
+
assert_equal "#00ffff",
|
27
|
+
Rgb2Hex.convert(0, 255, 255)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_throws_exeption_when_num_less_than_0
|
31
|
+
exception = assert_raise(ArgumentError) do
|
32
|
+
Rgb2Hex.convert(-1, 0, 0)
|
33
|
+
end
|
34
|
+
assert_equal "input argument is less than 0", exception.message
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_throws_exeption_when_num_more_than_255
|
38
|
+
exception = assert_raise(ArgumentError) do
|
39
|
+
Rgb2Hex.convert(0, 0, 256)
|
40
|
+
end
|
41
|
+
assert_equal "input argument is more than 255", exception.message
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_throws_exeption_when_multiple_nums_more_than_255
|
45
|
+
exception = assert_raise(ArgumentError) do
|
46
|
+
Rgb2Hex.convert(0, 1001, 256)
|
47
|
+
end
|
48
|
+
assert_equal "input argument is more than 255", exception.message
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_throws_exeption_when_nums_are_less_than_0_and_more_than_255
|
52
|
+
exception = assert_raise(ArgumentError) do
|
53
|
+
Rgb2Hex.convert(362, 1001, -10)
|
54
|
+
end
|
55
|
+
assert_equal "input argument is less than 0", exception.message
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_dirty_inputs
|
59
|
+
assert_equal "#ff0090",
|
60
|
+
Rgb2Hex.convert("255", "0", "144")
|
61
|
+
|
62
|
+
assert_equal "#ff0090",
|
63
|
+
Rgb2Hex.convert("255,", "0,", "144,")
|
64
|
+
|
65
|
+
assert_equal "#ff0090",
|
66
|
+
Rgb2Hex.convert("255,", "sadf0,", "- 144,")
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_single_argument
|
70
|
+
assert_equal "#ffffff",
|
71
|
+
Rgb2Hex.convert("255, 255, 255")
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_some_more_single_arguments
|
75
|
+
assert_equal "#00ffff",
|
76
|
+
Rgb2Hex.convert("rgb(0, 255, 255)")
|
77
|
+
assert_equal "#00ffff",
|
78
|
+
Rgb2Hex.convert("rgb[0; 255; 255]")
|
79
|
+
assert_equal "#00ffff",
|
80
|
+
Rgb2Hex.convert("rgb[0; 255; 255]")
|
81
|
+
assert_equal "#00ffff",
|
82
|
+
Rgb2Hex.convert("rgb[0; 255; 255]")
|
83
|
+
assert_equal "#010203",
|
84
|
+
Rgb2Hex.convert("red=1 green=2 blue=3")
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_illegal_number_of_input_args
|
88
|
+
assert_equal "illegal number of input arguments",
|
89
|
+
Rgb2Hex.convert(1, 2)
|
90
|
+
end
|
91
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgb2hex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Zelenkov
|
@@ -9,21 +9,40 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2013-07-26 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
13
|
-
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.1'
|
27
|
+
description: |2
|
28
|
+
Converts RGB values to HEX value
|
14
29
|
email: zj@jz.ee
|
15
30
|
executables:
|
16
31
|
- rgb2hex
|
17
32
|
extensions: []
|
18
|
-
extra_rdoc_files:
|
33
|
+
extra_rdoc_files:
|
34
|
+
- README.md
|
19
35
|
files:
|
20
36
|
- lib/rgb2hex.rb
|
21
37
|
- bin/rgb2hex
|
38
|
+
- Rakefile
|
39
|
+
- README.md
|
40
|
+
- test/test_rgb2hex.rb
|
22
41
|
homepage: https://github.com/zjjz/180-tools/tree/master/001-rgb2hex
|
23
42
|
licenses:
|
24
43
|
- MIT
|
25
44
|
metadata: {}
|
26
|
-
post_install_message:
|
45
|
+
post_install_message: Thanks for installing!
|
27
46
|
rdoc_options: []
|
28
47
|
require_paths:
|
29
48
|
- lib
|
@@ -31,7 +50,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
50
|
requirements:
|
32
51
|
- - '>='
|
33
52
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
53
|
+
version: 1.9.2
|
35
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
55
|
requirements:
|
37
56
|
- - '>='
|
@@ -43,4 +62,5 @@ rubygems_version: 2.0.3
|
|
43
62
|
signing_key:
|
44
63
|
specification_version: 4
|
45
64
|
summary: RGB -> HEX
|
46
|
-
test_files:
|
65
|
+
test_files:
|
66
|
+
- test/test_rgb2hex.rb
|