colorable 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b79f5456ff48188f4232decead4443e0c511ba3f
4
- data.tar.gz: cf8e2236927be3b23baaec50d220d112190076b5
3
+ metadata.gz: 8e870f136d2f8363c6504a6791b6d92c685a8c5b
4
+ data.tar.gz: 2324269b150e3a0b185d58484450db732030327b
5
5
  SHA512:
6
- metadata.gz: a7fc1f13cefb37d408c10491150020f788445693855b9a07d39c3653298d739f5f4b3f4de4f8d7e3fe5e2db58f0d3976d0982a167b330c54558c9abb768bc87d
7
- data.tar.gz: 66a27bbed8977cd6b543b86eb947a7fa5b9ece0fa5a40d1d7e0e7d110ac26b2472f3b69348bb9a83e7b7c69651459512a91c856c7e7b84fc91dfdda5280f6368
6
+ metadata.gz: d35c078bc35373898eca3265be0b4dc19767e790216449da4b6d1032bcbe049f836433c832fee36ffb6326223d5babaeeb646ae7e6f9e852dea21ffce3c5e910
7
+ data.tar.gz: ec49752c31853f8cdbe151f3152c51f00e6237727c1e2232d4a27bd7225fae4a0ad8e18313e0456b34268bd88ee867b0b18ed6603716e90c770d927a7c358c45
data/README.md CHANGED
@@ -87,6 +87,19 @@ Color object has a mode which represent output mode of the color. Behaviours of
87
87
  (c + 10).to_s #=> "rgb(60,215,60)"
88
88
  (c + [0, 50, 100]).to_s #=> "rgb(50, 255, 150)"
89
89
 
90
+ Shortcut for creating a color object with #to_color of String, Symbol and Array:
91
+
92
+ c = "Lime Green".to_color
93
+ c.class #=> Colorable::Color
94
+
95
+ c = :lime_green.to_color
96
+ c.class #=> Colorable::Color
97
+
98
+ c = "#32CD32".to_color
99
+ c.class #=> Colorable::Color
100
+
101
+ c = [50, 205, 50].to_color
102
+ c.class #=> Colorable::Color
90
103
 
91
104
  Create a X11 colorset object:
92
105
 
data/lib/colorable.rb CHANGED
@@ -6,9 +6,12 @@ module Colorable
6
6
  # Based on X11 color names - Wikipedia, the free encyclopedia
7
7
  # http://en.wikipedia.org/wiki/X11_color_names
8
8
  # When W3C color conflict with X11, a name of the color is appended with '2'.
9
- COLORNAMES = [["Alice Blue", [240, 248, 255]], ["Antique White", [250, 235, 215]], ["Aqua", [0, 255, 255]], ["Aquamarine", [127, 255, 212]], ["Azure", [240, 255, 255]], ["Beige", [245, 245, 220]], ["Bisque", [255, 228, 196]], ["Black", [0, 0, 0]], ["Blanched Almond", [255, 235, 205]], ["Blue", [0, 0, 255]], ["Blue Violet", [138, 43, 226]], ["Brown", [165, 42, 42]], ["Burlywood", [222, 184, 135]], ["Cadet Blue", [95, 158, 160]], ["Chartreuse", [127, 255, 0]], ["Chocolate", [210, 105, 30]], ["Coral", [255, 127, 80]], ["Cornflower", [100, 149, 237]], ["Cornsilk", [255, 248, 220]], ["Crimson", [220, 20, 60]], ["Cyan", [0, 255, 255]], ["Dark Blue", [0, 0, 139]], ["Dark Cyan", [0, 139, 139]], ["Dark Goldenrod", [184, 134, 11]], ["Dark Gray", [169, 169, 169]], ["Dark Green", [0, 100, 0]], ["Dark Khaki", [189, 183, 107]], ["Dark Magenta", [139, 0, 139]], ["Dark Olive Green", [85, 107, 47]], ["Dark Orange", [255, 140, 0]], ["Dark Orchid", [153, 50, 204]], ["Dark Red", [139, 0, 0]], ["Dark Salmon", [233, 150, 122]], ["Dark Sea Green", [143, 188, 143]], ["Dark Slate Blue", [72, 61, 139]], ["Dark Slate Gray", [47, 79, 79]], ["Dark Turquoise", [0, 206, 209]], ["Dark Violet", [148, 0, 211]], ["Deep Pink", [255, 20, 147]], ["Deep Sky Blue", [0, 191, 255]], ["Dim Gray", [105, 105, 105]], ["Dodger Blue", [30, 144, 255]], ["Firebrick", [178, 34, 34]], ["Floral White", [255, 250, 240]], ["Forest Green", [34, 139, 34]], ["Fuchsia", [255, 0, 255]], ["Gainsboro", [220, 220, 220]], ["Ghost White", [248, 248, 255]], ["Gold", [255, 215, 0]], ["Goldenrod", [218, 165, 32]], ["Gray", [190, 190, 190]], ["Gray2", [128, 128, 128]], ["Green", [0, 255, 0]], ["Green Yellow", [173, 255, 47]], ["Green2", [0, 128, 0]], ["Honeydew", [240, 255, 240]], ["Hot Pink", [255, 105, 180]], ["Indian Red", [205, 92, 92]], ["Indigo", [75, 0, 130]], ["Ivory", [255, 255, 240]], ["Khaki", [240, 230, 140]], ["Lavender", [230, 230, 250]], ["Lavender Blush", [255, 240, 245]], ["Lawn Green", [124, 252, 0]], ["Lemon Chiffon", [255, 250, 205]], ["Light Blue", [173, 216, 230]], ["Light Coral", [240, 128, 128]], ["Light Cyan", [224, 255, 255]], ["Light Goldenrod", [250, 250, 210]], ["Light Gray", [211, 211, 211]], ["Light Green", [144, 238, 144]], ["Light Pink", [255, 182, 193]], ["Light Salmon", [255, 160, 122]], ["Light Sea Green", [32, 178, 170]], ["Light Sky Blue", [135, 206, 250]], ["Light Slate Gray", [119, 136, 153]], ["Light Steel Blue", [176, 196, 222]], ["Light Yellow", [255, 255, 224]], ["Lime", [0, 255, 0]], ["Lime Green", [50, 205, 50]], ["Linen", [250, 240, 230]], ["Magenta", [255, 0, 255]], ["Maroon", [176, 48, 96]], ["Maroon2", [127, 0, 0]], ["Medium Aquamarine", [102, 205, 170]], ["Medium Blue", [0, 0, 205]], ["Medium Orchid", [186, 85, 211]], ["Medium Purple", [147, 112, 219]], ["Medium Sea Green", [60, 179, 113]], ["Medium Slate Blue", [123, 104, 238]], ["Medium Spring Green", [0, 250, 154]], ["Medium Turquoise", [72, 209, 204]], ["Medium Violet Red", [199, 21, 133]], ["Midnight Blue", [25, 25, 112]], ["Mint Cream", [245, 255, 250]], ["Misty Rose", [255, 228, 225]], ["Moccasin", [255, 228, 181]], ["Navajo White", [255, 222, 173]], ["Navy", [0, 0, 128]], ["Old Lace", [253, 245, 230]], ["Olive", [128, 128, 0]], ["Olive Drab", [107, 142, 35]], ["Orange", [255, 165, 0]], ["Orange Red", [255, 69, 0]], ["Orchid", [218, 112, 214]], ["Pale Goldenrod", [238, 232, 170]], ["Pale Green", [152, 251, 152]], ["Pale Turquoise", [175, 238, 238]], ["Pale Violet Red", [219, 112, 147]], ["Papaya Whip", [255, 239, 213]], ["Peach Puff", [255, 218, 185]], ["Peru", [205, 133, 63]], ["Pink", [255, 192, 203]], ["Plum", [221, 160, 221]], ["Powder Blue", [176, 224, 230]], ["Purple", [160, 32, 240]], ["Purple2", [127, 0, 127]], ["Red", [255, 0, 0]], ["Rosy Brown", [188, 143, 143]], ["Royal Blue", [65, 105, 225]], ["Saddle Brown", [139, 69, 19]], ["Salmon", [250, 128, 114]], ["Sandy Brown", [244, 164, 96]], ["Sea Green", [46, 139, 87]], ["Seashell", [255, 245, 238]], ["Sienna", [160, 82, 45]], ["Silver", [192, 192, 192]], ["Sky Blue", [135, 206, 235]], ["Slate Blue", [106, 90, 205]], ["Slate Gray", [112, 128, 144]], ["Snow", [255, 250, 250]], ["Spring Green", [0, 255, 127]], ["Steel Blue", [70, 130, 180]], ["Tan", [210, 180, 140]], ["Teal", [0, 128, 128]], ["Thistle", [216, 191, 216]], ["Tomato", [255, 99, 71]], ["Turquoise", [64, 224, 208]], ["Violet", [238, 130, 238]], ["Wheat", [245, 222, 179]], ["White", [255, 255, 255]], ["White Smoke", [245, 245, 245]], ["Yellow", [255, 255, 0]], ["Yellow Green", [154, 205, 50]]]
9
+ COLORNAMES = [["Alice Blue", [240, 248, 255]], ["Antique White", [250, 235, 215]], ["Aqua", [0, 255, 255]], ["Aquamarine", [127, 255, 212]], ["Azure", [240, 255, 255]], ["Beige", [245, 245, 220]], ["Bisque", [255, 228, 196]], ["Black", [0, 0, 0]], ["Blanched Almond", [255, 235, 205]], ["Blue", [0, 0, 255]], ["Blue Violet", [138, 43, 226]], ["Brown", [165, 42, 42]], ["Burlywood", [222, 184, 135]], ["Cadet Blue", [95, 158, 160]], ["Chartreuse", [127, 255, 0]], ["Chocolate", [210, 105, 30]], ["Coral", [255, 127, 80]], ["Cornflower", [100, 149, 237]], ["Cornsilk", [255, 248, 220]], ["Crimson", [220, 20, 60]], ["Cyan", [0, 255, 255]], ["Dark Blue", [0, 0, 139]], ["Dark Cyan", [0, 139, 139]], ["Dark Goldenrod", [184, 134, 11]], ["Dark Gray", [169, 169, 169]], ["Dark Green", [0, 100, 0]], ["Dark Khaki", [189, 183, 107]], ["Dark Magenta", [139, 0, 139]], ["Dark Olive Green", [85, 107, 47]], ["Dark Orange", [255, 140, 0]], ["Dark Orchid", [153, 50, 204]], ["Dark Red", [139, 0, 0]], ["Dark Salmon", [233, 150, 122]], ["Dark Sea Green", [143, 188, 143]], ["Dark Slate Blue", [72, 61, 139]], ["Dark Slate Gray", [47, 79, 79]], ["Dark Turquoise", [0, 206, 209]], ["Dark Violet", [148, 0, 211]], ["Deep Pink", [255, 20, 147]], ["Deep Sky Blue", [0, 191, 255]], ["Dim Gray", [105, 105, 105]], ["Dodger Blue", [30, 144, 255]], ["Firebrick", [178, 34, 34]], ["Floral White", [255, 250, 240]], ["Forest Green", [34, 139, 34]], ["Fuchsia", [255, 0, 255]], ["Gainsboro", [220, 220, 220]], ["Ghost White", [248, 248, 255]], ["Gold", [255, 215, 0]], ["Goldenrod", [218, 165, 32]], ["Gray", [190, 190, 190]], ["Gray2", [128, 128, 128]], ["Green", [0, 255, 0]], ["Green Yellow", [173, 255, 47]], ["Green2", [0, 128, 0]], ["Honeydew", [240, 255, 240]], ["Hot Pink", [255, 105, 180]], ["Indian Red", [205, 92, 92]], ["Indigo", [75, 0, 130]], ["Ivory", [255, 255, 240]], ["Khaki", [240, 230, 140]], ["Lavender", [230, 230, 250]], ["Lavender Blush", [255, 240, 245]], ["Lawn Green", [124, 252, 0]], ["Lemon Chiffon", [255, 250, 205]], ["Light Blue", [173, 216, 230]], ["Light Coral", [240, 128, 128]], ["Light Cyan", [224, 255, 255]], ["Light Goldenrod", [250, 250, 210]], ["Light Gray", [211, 211, 211]], ["Light Green", [144, 238, 144]], ["Light Pink", [255, 182, 193]], ["Light Salmon", [255, 160, 122]], ["Light Sea Green", [32, 178, 170]], ["Light Sky Blue", [135, 206, 250]], ["Light Slate Gray", [119, 136, 153]], ["Light Steel Blue", [176, 196, 222]], ["Light Yellow", [255, 255, 224]], ["Lime", [0, 255, 0]], ["Lime Green", [50, 205, 50]], ["Linen", [250, 240, 230]], ["Magenta", [255, 0, 255]], ["Maroon", [176, 48, 96]], ["Maroon2", [127, 0, 0]], ["Medium Aquamarine", [102, 205, 170]], ["Medium Blue", [0, 0, 205]], ["Medium Orchid", [186, 85, 211]], ["Medium Purple", [147, 112, 219]], ["Medium Sea Green", [60, 179, 113]], ["Medium Slate Blue", [123, 104, 238]], ["Medium Spring Green", [0, 250, 154]], ["Medium Turquoise", [72, 209, 204]], ["Medium Violet Red", [199, 21, 133]], ["Midnight Blue", [25, 25, 112]], ["Mint Cream", [245, 255, 250]], ["Misty Rose", [255, 228, 225]], ["Moccasin", [255, 228, 181]], ["Navajo White", [255, 222, 173]], ["Navy", [0, 0, 128]], ["Old Lace", [253, 245, 230]], ["Olive", [128, 128, 0]], ["Olive Drab", [107, 142, 35]], ["Orange", [255, 165, 0]], ["Orange Red", [255, 69, 0]], ["Orchid", [218, 112, 214]], ["Pale Goldenrod", [238, 232, 170]], ["Pale Green", [152, 251, 152]], ["Pale Turquoise", [175, 238, 238]], ["Pale Violet Red", [219, 112, 147]], ["Papaya Whip", [255, 239, 213]], ["Peach Puff", [255, 218, 185]], ["Peru", [205, 133, 63]], ["Pink", [255, 192, 203]], ["Plum", [221, 160, 221]], ["Powder Blue", [176, 224, 230]], ["Purple", [160, 32, 240]], ["Purple2", [127, 0, 127]], ["Red", [255, 0, 0]], ["Rosy Brown", [188, 143, 143]], ["Royal Blue", [65, 105, 225]], ["Saddle Brown", [139, 69, 19]], ["Salmon", [250, 128, 114]], ["Sandy Brown", [244, 164, 96]], ["Sea Green", [46, 139, 87]], ["Seashell", [255, 245, 238]], ["Sienna", [160, 82, 45]], ["Silver", [192, 192, 192]], ["Sky Blue", [135, 206, 235]], ["Slate Blue", [106, 90, 205]], ["Slate Gray", [112, 128, 144]], ["Snow", [255, 250, 250]], ["Spring Green", [0, 255, 127]], ["Steel Blue", [70, 130, 180]], ["Tan", [210, 180, 140]], ["Teal", [0, 128, 128]], ["Thistle", [216, 191, 216]], ["Tomato", [255, 99, 71]], ["Turquoise", [64, 224, 208]], ["Violet", [238, 130, 238]], ["Wheat", [245, 222, 179]], ["White", [255, 255, 255]], ["White Smoke", [245, 245, 245]], ["Yellow", [255, 255, 0]], ["Yellow Green", [154, 205, 50]]].freeze
10
10
 
11
- DARK_COLORS = ["Black", "Dark Green", "Dark Olive Green", "Dark Slate Gray", "Dim Gray", "Gray", "Indigo", "Midnight Blue", "Navy", "Navy Blue", "Blue Violet", "Brown", "Dark Slate Blue", "Dark Violet", "Firebrick", "Medium Blue", "Medium Violet Red", "Saddle Brown"]
11
+ DARK_COLORS = ["Black", "Dark Green", "Dark Olive Green", "Dark Slate Gray", "Dim Gray", "Gray", "Indigo", "Midnight Blue", "Navy", "Navy Blue", "Blue Violet", "Brown", "Dark Slate Blue", "Dark Violet", "Firebrick", "Medium Blue", "Medium Violet Red", "Saddle Brown"].freeze
12
12
 
13
13
  end
14
14
 
15
+ [String, Symbol, Array].each do |klass|
16
+ klass.define_method(:to_color) { Colorable::Color.new self }
17
+ end
@@ -118,6 +118,7 @@ module Colorable
118
118
  mode = name
119
119
  end
120
120
  when Array
121
+ raise ArgumentError, 'Invalid Array given' unless arg.size==3
121
122
  rgb = RGB.new *arg
122
123
  name = NAME.new(rgb.to_name) rescue nil
123
124
  hsb = nil
@@ -1,3 +1,3 @@
1
1
  module Colorable
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/spec/color_spec.rb CHANGED
@@ -54,6 +54,7 @@ describe Color do
54
54
  context "of invalid RGB value" do
55
55
  it "raise an error" do
56
56
  expect { Color.new([200, 100, 260]) }.to raise_error ArgumentError
57
+ expect { Color.new([200, 100]) }.to raise_error ArgumentError
57
58
  end
58
59
  end
59
60
  end
@@ -0,0 +1,53 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Colorable do
4
+ describe "String#to_color" do
5
+ context "apply a colorname string" do
6
+ subject { "Lime Green".to_color }
7
+ it { should be_instance_of Colorable::Color }
8
+ its(:to_s) { should eql "Lime Green" }
9
+ end
10
+
11
+ context "apply a hex string" do
12
+ subject { "#32CD32".to_color }
13
+ it { should be_instance_of Colorable::Color }
14
+ its(:to_s) { should eql "#32CD32" }
15
+ end
16
+
17
+ context "apply a invalid string" do
18
+ it "raise ArgumentError" do
19
+ expect { "Bad Green".to_color }.to raise_error ArgumentError
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "Symbol#to_color" do
25
+ context "apply a colorname symbol" do
26
+ subject { :lime_green.to_color }
27
+ it { should be_instance_of Colorable::Color }
28
+ its(:to_s) { should eql "Lime Green" }
29
+ end
30
+
31
+ context "apply a invalid symbol" do
32
+ it "raise ArgumentError" do
33
+ expect { :bad_green.to_color }.to raise_error ArgumentError
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "Array#to_color" do
39
+ context "apply a RGB values" do
40
+ subject { [50, 205, 50].to_color }
41
+ it { should be_instance_of Colorable::Color }
42
+ its(:to_s) { should eql "rgb(50,205,50)" }
43
+ end
44
+
45
+ context "apply a invalid array" do
46
+ it "raise ArgumentError" do
47
+ expect { [50, 205].to_color }.to raise_error ArgumentError
48
+ expect { [50, 205, 300].to_color }.to raise_error ArgumentError
49
+ expect { ['50', '205', '205'].to_color }.to raise_error ArgumentError
50
+ end
51
+ end
52
+ end
53
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colorable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kyoendo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-09 00:00:00.000000000 Z
11
+ date: 2013-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -47,6 +47,7 @@ files:
47
47
  - lib/colorable/version.rb
48
48
  - spec/color_space_spec.rb
49
49
  - spec/color_spec.rb
50
+ - spec/colorable_spec.rb
50
51
  - spec/colorset_spec.rb
51
52
  - spec/converter_spec.rb
52
53
  - spec/spec_helper.rb
@@ -77,6 +78,7 @@ summary: A simple color handler which provide a conversion between colorname, RG
77
78
  test_files:
78
79
  - spec/color_space_spec.rb
79
80
  - spec/color_spec.rb
81
+ - spec/colorable_spec.rb
80
82
  - spec/colorset_spec.rb
81
83
  - spec/converter_spec.rb
82
84
  - spec/spec_helper.rb