colcolor 0.0.1 → 0.0.2

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: 5347ef03ca37dd6d366489635ccd5f6d4a8ab378
4
- data.tar.gz: 33257625f3db686621035ade7d45e1c8da50e94a
3
+ metadata.gz: 2b446b52f24f036ce96faa3871612c17f3c1e283
4
+ data.tar.gz: 2b86dacefabce35110164cf3a926eaf65d679a90
5
5
  SHA512:
6
- metadata.gz: 78221ccecdadf899e29ac7c77a6cae5458604f69cbb10dafbf71f93b4e77b83da0f3a52c2ea09041a70c36af359d7bb9df2c1cfafde90b4ecb41f5202eb60de4
7
- data.tar.gz: 06628df1c918fe35a53a4a0df5e27e9f54128370032030876c3ad668dcdd7a64efaa89a2909389622a9a88fb64dc519e5ddfad97c3fd4129d7b36a9b2786b16e
6
+ metadata.gz: e6892c801857814a2b72b9ee6635b96d999be9364f1015d5166ecacfd5fc770bf67ed8a08384a3c617679ff5972c97199aebd3ebecf3288a6e1f9a7729ce0502
7
+ data.tar.gz: 0ef2a6ff5fb5946c136a5170e1ad89eb4ba653ace9538e4e4a0af4f1b0ee20839e72b5f15539eff7a16076788987bd879b8ee3fd5dd5d80f9ce5b23b66fdf8ff
@@ -1,23 +1,13 @@
1
1
  require "colcolor/version"
2
2
 
3
3
  module Colcolor
4
- COLORS = Hash[
5
- %i( black red green yellow blue magenta cyan white )
6
- .zip(30..37)
7
- .map { |k,v| [k, "\e[#{v}m"] }
8
- ].freeze
9
-
10
- BGCOLORS = Hash[
11
- %i( black red green yellow blue magenta cyan white )
12
- .zip(40..47)
13
- .map { |k,v| [k, "\e[#{v}m"] }
14
- ].freeze
4
+ def self.TAGMAP(colors, codes)
5
+ Hash[ colors.zip(codes).map { |k, v| [k, "\e[#{v}m"] } ].freeze
6
+ end
15
7
 
16
- EXTRA = Hash[
17
- %i( clear bold underline blink reverse )
18
- .zip([0, 1, 4, 5, 7])
19
- .map { |k,v| [k, "\e[#{v}m"] }
20
- ].freeze
8
+ COLORS = TAGMAP( %i(black red green yellow blue magenta cyan white), 30..37)
9
+ BGCOLORS = TAGMAP( %i( black red green yellow blue magenta cyan white), 40..47)
10
+ EXTRA = TAGMAP( %i( clear bold underline blink reverse ), [0, 1, 4, 5, 7])
21
11
 
22
12
  def colco(*colors, regexp:/\S+/)
23
13
  cs = colors.dup
@@ -29,7 +19,7 @@ module Colcolor
29
19
 
30
20
  private
31
21
  def build_color_tag(name)
32
- if tag = COLORS[name] || BGCOLORS["bg_#{name}".intern] || EXTRA[name]
22
+ if tag = COLORS[name] || BGCOLORS[name] || EXTRA[name]
33
23
  tag
34
24
  else
35
25
  fore, *ext = name.to_s.split('_').map(&:intern)
@@ -1,3 +1,3 @@
1
1
  module Colcolor
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -16,6 +16,12 @@ describe Colcolor do
16
16
  color_set = [:green, :yellow, :red]
17
17
  expect(@str.colco(*color_set)).to eq expect
18
18
  end
19
+
20
+ it "colors background of words" do
21
+ expect = "\e[42mGeorge\e[0m \e[43m18\e[0m \e[41mguitarist\e[0m"
22
+ color_set = [:bg_green, :bg_yellow, :bg_red]
23
+ expect(@str.colco(*color_set)).to eq expect
24
+ end
19
25
  end
20
26
 
21
27
  context "two or more color attributes to a word" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colcolor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kyoendo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-14 00:00:00.000000000 Z
11
+ date: 2014-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler