hex2rgb 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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -0
  3. data/Rakefile +8 -0
  4. data/test/test_hex2rgb.rb +98 -0
  5. metadata +27 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffe1a0f2c81659bd5ce4ad790f5ceb5af7a30dc6
4
- data.tar.gz: 2bf50af0a4784223226f75911e60ce1d9856a485
3
+ metadata.gz: d17db462677c03f2f30f11ae9183b55f5b1c4c5f
4
+ data.tar.gz: 90b15a58267df4a84ced8ed324609f89ad6424c5
5
5
  SHA512:
6
- metadata.gz: ca21648b29644dd80188441ac75675f796f8a5d08d2d5e2cda2fde1ae0c31d8cde12e10c74bd82958c3eba510d896222f129599cd9367a95d91b72db18c03a7b
7
- data.tar.gz: df9f8c9d987583b01258f37f4c4fedad8e5f8705623a670814bda6e22ea25874799934ec5c68f973fbdbb22ec6b86ccdcfb70dc4ba9e765a2ee76a16be130de2
6
+ metadata.gz: 9be90bb9edf06a339b164bccff0777970ee704a307f740341a4fe077e76f97b00c13240d0064863a04c3978f388ac54a7818ec51b99cd5f5701403cbc5d933fe
7
+ data.tar.gz: be38ab3911d9ca8bbb04b4b3bc342750126c4cb3fb1dfd19007790d6b37ae2f1eda55b8e6a00ac0f988e4c780b2ccec39bce158a985a7bb178d6db1a3aac7df9
@@ -0,0 +1,20 @@
1
+ # Day 2. Hex2Rgb
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/hex2rgb.png)](http://badge.fury.io/rb/hex2rgb)
4
+ [![Build Status](https://travis-ci.org/zjjz/180-tools.png)](https://travis-ci.org/zjjz/180-tools)
5
+
6
+
7
+ `Hex2Rgb` is a ruby gem which lets you quickly convert HEX value of any color to its RGB value. Another useful utility is [rgb2hex](https://github.com/zjjz/180-tools/tree/master/001-rgb2hex).
8
+
9
+
10
+ ## Usage
11
+
12
+ `Hex2Rgb` expects a hex value either in a full form (6 chars) or in the short form (3 chars). Hash symbol `#` at the beginnig is optional. It produces an RGB value triplet surrounded with square brackets
13
+
14
+ >> hex2rgb ff0090 # magenta
15
+ => [255, 0, 144]
16
+
17
+ In mac osx terminal, `#` char should be escaped for `hex2rgb` to work, e.g.
18
+
19
+ >> hex2rgb \#ff0090
20
+ => [255, 0, 144]
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -0,0 +1,98 @@
1
+ require 'test/unit'
2
+ require 'hex2rgb'
3
+
4
+ class Rgb2HexTest < Test::Unit::TestCase
5
+ def test_defaults_to_black
6
+ assert_equal "[0, 0, 0]",
7
+ Hex2Rgb.convert
8
+ end
9
+
10
+ def test_converts_black
11
+ assert_equal "[0, 0, 0]",
12
+ Hex2Rgb.convert("#000000")
13
+ end
14
+
15
+ def test_converts_white
16
+ assert_equal "[255, 255, 255]",
17
+ Hex2Rgb.convert("#ffffff")
18
+ end
19
+
20
+ def test_converts_magenta
21
+ assert_equal "[255, 0, 144]",
22
+ Hex2Rgb.convert("#ff0090")
23
+ end
24
+
25
+ def test_converts_cyan
26
+ assert_equal "[0, 255, 255]",
27
+ Hex2Rgb.convert("#00ffff")
28
+ end
29
+
30
+ def test_converts_yellow
31
+ assert_equal "[255, 255, 0]",
32
+ Hex2Rgb.convert("#ffff00")
33
+ end
34
+
35
+ def test_converts_yellow_uppercase
36
+ assert_equal "[255, 255, 0]",
37
+ Hex2Rgb.convert("#FFFF00")
38
+ end
39
+
40
+ def test_converts_cyan_no_hash
41
+ assert_equal "[0, 255, 255]",
42
+ Hex2Rgb.convert("00ffff")
43
+ end
44
+
45
+ def test_converts_purple_no_hash
46
+ assert_equal "[128, 0, 128]",
47
+ Hex2Rgb.convert("800080")
48
+ end
49
+
50
+ def test_converts_short_black
51
+ assert_equal "[0, 0, 0]",
52
+ Hex2Rgb.convert("#000")
53
+ end
54
+
55
+ def test_converts_short_white_no_hash
56
+ assert_equal "[255, 255, 255]",
57
+ Hex2Rgb.convert("fff")
58
+ end
59
+
60
+ def test_throws_exception_for_non_hex_value
61
+ exception = assert_raise(ArgumentError) do
62
+ Hex2Rgb.convert("#fh0090")
63
+ end
64
+ assert_equal "only chars in ranges 0-9 and a-f are allowed", exception.message
65
+ end
66
+
67
+ def test_throws_exception_for_wrong_input_arg_length
68
+ exception = assert_raise(ArgumentError) do
69
+ Hex2Rgb.convert("#ff00900")
70
+ end
71
+ assert_equal "wrong input argument length", exception.message
72
+
73
+ exception = assert_raise(ArgumentError) do
74
+ Hex2Rgb.convert("#ff009")
75
+ end
76
+ assert_equal "wrong input argument length", exception.message
77
+
78
+ exception = assert_raise(ArgumentError) do
79
+ Hex2Rgb.convert("#ff00")
80
+ end
81
+ assert_equal "wrong input argument length", exception.message
82
+
83
+ exception = assert_raise(ArgumentError) do
84
+ Hex2Rgb.convert("#ff")
85
+ end
86
+ assert_equal "wrong input argument length", exception.message
87
+
88
+ exception = assert_raise(ArgumentError) do
89
+ Hex2Rgb.convert("#f")
90
+ end
91
+ assert_equal "wrong input argument length", exception.message
92
+
93
+ exception = assert_raise(ArgumentError) do
94
+ Hex2Rgb.convert("f")
95
+ end
96
+ assert_equal "wrong input argument length", exception.message
97
+ end
98
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hex2rgb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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-27 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Converts HEX value to RGB values
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 HEX value to RGB values"
14
29
  email: zj@jz.ee
15
30
  executables:
16
31
  - hex2rgb
17
32
  extensions: []
18
- extra_rdoc_files: []
33
+ extra_rdoc_files:
34
+ - README.md
19
35
  files:
20
36
  - lib/hex2rgb.rb
21
37
  - bin/hex2rgb
38
+ - Rakefile
39
+ - README.md
40
+ - test/test_hex2rgb.rb
22
41
  homepage: https://github.com/zjjz/180-tools/tree/master/002-hex2rgb
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: '0'
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: HEX -> RGB
46
- test_files: []
65
+ test_files:
66
+ - test/test_hex2rgb.rb