reggieb 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,6 @@
1
+ 0.1.0 (October 2, 2009)
2
+ * Added ability to accept rgb colors specified as percentages:
3
+ rgb(50%, 34%, 12%)
4
+
5
+ 0.0.1 (September 27, 2009)
6
+ * Initial release.
data/README CHANGED
@@ -2,13 +2,18 @@
2
2
 
3
3
  == Description
4
4
 
5
+ This is not the gem that you want. You want the full-featured "color" Ruby gem.
6
+
7
+ You're still here? Okay, this is what this gem is all about:
8
+
5
9
  Reggie B. is a utility for converting colors between rgb and hex format. It was created
6
- to support http://www.2rgb.com.
10
+ to support http://www.2rgb.com. It is especially useful for handling CSS color formats.
7
11
 
8
12
  == Examples
9
13
 
10
- ReggieB.convert "rgb(255, 255, 255)" => "0xffffff"
11
- ReggieB.convert "255, 255, 255" => "0xffffff"
12
- ReggieB.convert "0xffffff" => [255, 255, 255]
13
- ReggieB.convert "#ffffff" => [255, 255, 255]
14
- ReggieB.convert "#fff" => [255, 255, 255]
14
+ ReggieB.convert "rgb(255, 255, 255)" => "0xffffff"
15
+ ReggieB.convert "255, 255, 255" => "0xffffff"
16
+ ReggieB.convert "rgb(100%, 100%, 100%)" => "0xffffff"
17
+ ReggieB.convert "0xffffff" => [255, 255, 255]
18
+ ReggieB.convert "#ffffff" => [255, 255, 255]
19
+ ReggieB.convert "#fff" => [255, 255, 255]
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ end
24
24
 
25
25
  gem_spec = Gem::Specification.new do |s|
26
26
  s.name = "reggieb"
27
- s.version = "0.0.1"
27
+ s.version = "0.1.0"
28
28
  s.author = "Wyatt Greene"
29
29
  s.email = "techiferous@gmail.com"
30
30
  s.summary = "A Hex/RGB color converter."
@@ -33,7 +33,9 @@ gem_spec = Gem::Specification.new do |s|
33
33
  It is very forgiving in the syntax it allows.
34
34
  }
35
35
  s.require_path = "lib"
36
- s.files = FileList["lib/**/*.rb", "[A-Z]*", "test/**/*"].to_a
36
+ s.files = ["lib/reggieb.rb", "LICENSE", "Rakefile", "README",
37
+ "CHANGELOG",
38
+ "test/reggieb_test.rb", "test/test_helper.rb"]
37
39
  s.homepage = "http://github.com/techiferous/reggieb"
38
40
  s.requirements << "none"
39
41
  s.has_rdoc = true
data/lib/reggieb.rb CHANGED
@@ -9,6 +9,8 @@ class ReggieB
9
9
  # - "(255, 255, 255)"
10
10
  # - "255, 255, 255"
11
11
  # - "255 255 255"
12
+ # - "rgb(100%, 100%, 100%)"
13
+ # - "100% 100% 100%"
12
14
  # - "0xffffff"
13
15
  # - "0xFFFFFF"
14
16
  # - "#ffffff"
@@ -37,6 +39,10 @@ class ReggieB
37
39
  s = $2 + $2 + $3 + $3 + $4 + $4
38
40
  return to_rgb(s)
39
41
  end
42
+ if s =~ /^\D*(\d{1,3})%\D*(\d{1,3})%\D*(\d{1,3})%\D*$/
43
+ percent_to_byte = 255.0 / 100.0
44
+ return to_hex($1.to_i*percent_to_byte, $2.to_i*percent_to_byte, $3.to_i*percent_to_byte)
45
+ end
40
46
  if s =~ /^\D*(\d{1,3})\D+(\d{1,3})\D+(\d{1,3})\D*$/
41
47
  return to_hex($1.to_i, $2.to_i, $3.to_i)
42
48
  end
@@ -47,6 +53,9 @@ class ReggieB
47
53
  # is a string formatted like "0xdddddd" where d represents a hex digit.
48
54
  #
49
55
  def self.to_hex(r, g, b)
56
+ r = r.round
57
+ g = g.round
58
+ b = b.round
50
59
  unless (0..255).include?(r) && (0..255).include?(g) && (0..255).include?(b)
51
60
  message = "RGB values should be between 0 and 255. Received #{r}, #{g}, #{b}."
52
61
  raise ArgumentError.new(message)
data/test/reggieb_test.rb CHANGED
@@ -175,4 +175,14 @@ class ReggieBTest < Test::Unit::TestCase
175
175
  assert_equal "0xa01100", ReggieB.convert("rgb(160, 17, 0);")
176
176
  end
177
177
 
178
+ def test_rgb_percentages
179
+ assert_equal "0xffffff", ReggieB.convert("rgb(100%, 100%, 100%)")
180
+ assert_equal "0xff7f7f", ReggieB.convert("rgb(100%, 50%, 50%)")
181
+ assert_equal "0x000000", ReggieB.convert("rgb(0%, 0%, 0%)")
182
+ assert_equal "0xffffff", ReggieB.convert("rgb(100%, 100%, 100%);")
183
+ assert_equal "0x7fff7f", ReggieB.convert("50% 100% 50%")
184
+ assert_equal "0x7fff7f", ReggieB.convert(" 50% 100% 50% ")
185
+ assert_equal "0x7fff7f", ReggieB.convert("50%100%50%")
186
+ end
187
+
178
188
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reggieb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wyatt Greene
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-27 00:00:00 -04:00
12
+ date: 2009-10-02 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -26,6 +26,7 @@ files:
26
26
  - LICENSE
27
27
  - Rakefile
28
28
  - README
29
+ - CHANGELOG
29
30
  - test/reggieb_test.rb
30
31
  - test/test_helper.rb
31
32
  has_rdoc: true