colorize 0.7.5 → 0.7.6

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: 5daa22026f530e287e74e572407ba4ddf9520104
4
- data.tar.gz: 3af9a37ec77d130690c976cd1decbf4fc086a321
3
+ metadata.gz: 9e21c9389b1bb8d1cd8884565a5dbe6e2edb72d5
4
+ data.tar.gz: 87a1ccbaf344139c937dc2680d7825281c9f725b
5
5
  SHA512:
6
- metadata.gz: bcfa897a7e8bc2ce4fa354e192a22d53a8f81114ebe98ebbc7921ba99496b72b92771ba78ad2c3a1c34acd7c83a6e24c5e146ec92ca314283ba4c80675b78d09
7
- data.tar.gz: f3f2a9297ab0cac20506b1875e92f3cc0d476a7f053bb6d89941576b22662faa8a9a7970a54d9e64f1738d493e47c0578c35cff963077044cd1e739ebcf8b814
6
+ metadata.gz: bfd3eeaed2fc6b03c1fdc11dd99a73a0f438dd1324786675630b7ef70d59edce22a699d0a249088a189158c9aa790605a6b3ef4184c9dd0c790d74b95123e40d
7
+ data.tar.gz: 5556fc5742cd26ae473b35787767f8dafcd1d1950fae81fa3723f44ea83890de10879ac540094ebeda1a592effdeff2a119cc87b0c5ed275c095a0ce62bc15c6
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.7.6 / 2015-04-18
2
+ * fix bugs
3
+
1
4
  == 0.7.5 / 2014-12-11
2
5
  * big code refactoring
3
6
  * disable_colorization feature added
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
- colorize [![Gem Version](https://badge.fury.io/rb/colorize.svg)](http://badge.fury.io/rb/colorize) [![Build Status](https://travis-ci.org/fazibear/colorize.svg?branch=master)](https://travis-ci.org/fazibear/colorize) [![Code Climate](https://codeclimate.com/github/fazibear/colorize/badges/gpa.svg)](https://codeclimate.com/github/fazibear/colorize)
1
+ colorize [![Gem Version](https://badge.fury.io/rb/colorize.svg)](http://badge.fury.io/rb/colorize) [![Build Status](https://travis-ci.org/fazibear/colorize.svg?branch=master)](https://travis-ci.org/fazibear/colorize) [![Code Climate](https://codeclimate.com/github/fazibear/colorize/badges/gpa.svg)](https://codeclimate.com/github/fazibear/colorize) [![Test Coverage](https://codeclimate.com/github/fazibear/colorize/badges/coverage.svg)](https://codeclimate.com/github/fazibear/colorize)
2
2
  ========
3
-
3
+
4
4
  Ruby String class extension. Adds methods to set text color, background color and, text effects on ruby console and command line output, using ANSI escape sequences.
5
5
 
6
6
  features
7
7
  --------
8
-
8
+
9
9
  * change string color
10
10
  * change string background
11
11
  * change string effect
@@ -15,27 +15,31 @@ usage
15
15
 
16
16
  Some usage samples:
17
17
 
18
- puts "This is blue".colorize(:blue)
19
- puts "This is light blue".colorize(:light_blue)
20
- puts "This is also blue".colorize(:color => :blue)
21
- puts "This is light blue with red background".colorize(:color => :light_blue, :background => :red)
22
- puts "This is light blue with red background".colorize(:light_blue ).colorize( :background => :red)
23
- puts "This is blue text on red".blue.on_red
24
- puts "This is red on blue".colorize(:red).on_blue
25
- puts "This is red on blue and underline".colorize(:red).on_blue.underline
26
- puts "This is blue text on red".blue.on_red.blink
27
- puts "This is uncolorized".blue.on_red.uncolorize
18
+ ```ruby
19
+ puts "This is blue".colorize(:blue)
20
+ puts "This is light blue".colorize(:light_blue)
21
+ puts "This is also blue".colorize(:color => :blue)
22
+ puts "This is light blue with red background".colorize(:color => :light_blue, :background => :red)
23
+ puts "This is light blue with red background".colorize(:light_blue ).colorize( :background => :red)
24
+ puts "This is blue text on red".blue.on_red
25
+ puts "This is red on blue".colorize(:red).on_blue
26
+ puts "This is red on blue and underline".colorize(:red).on_blue.underline
27
+ puts "This is blue text on red".blue.on_red.blink
28
+ puts "This is uncolorized".blue.on_red.uncolorize
29
+ ```
28
30
 
29
31
  Class methods:
30
32
 
31
- String.colors - return array of all possible colors names
32
- String.modes - return array of all possible modes
33
- String.color_samples - displays color samples in all combinations
34
- String.disable_colorization - check if colorization is disabled
35
- String.disable_colorization = false - disable colorization
36
- String.disable_colorization false - disable colorization
37
- String.disable_colorization = true - enable colorization
38
- String.disable_colorization true - enable colorization
33
+ ```ruby
34
+ String.colors # return array of all possible colors names
35
+ String.modes # return array of all possible modes
36
+ String.color_samples # displays color samples in all combinations
37
+ String.disable_colorization # check if colorization is disabled
38
+ String.disable_colorization = false # enable colorization
39
+ String.disable_colorization false # enable colorization
40
+ String.disable_colorization = true # disable colorization
41
+ String.disable_colorization true # disable colorization
42
+ ```
39
43
 
40
44
  requirements
41
45
  ------------
@@ -52,7 +56,7 @@ install
52
56
  license
53
57
  -------
54
58
 
55
- Copyright (C) 2007-2015 Michal Kalbarczyk
59
+ Copyright (C) 2007-2015 Michał Kalbarczyk
56
60
 
57
61
  This program is free software; you can redistribute it and/or modify
58
62
  it under the terms of the GNU General Public License as published by
@@ -1,19 +1,23 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'colorize'
3
- s.version = '0.7.5'
3
+ s.version = '0.7.6'
4
4
 
5
- s.authors = ['fazibear']
5
+ s.authors = ['Michał Kalbarczyk']
6
6
  s.email = 'fazibear@gmail.com'
7
-
7
+
8
8
  s.date = Time.now.strftime("%Y-%m-%d")
9
-
9
+
10
10
  s.homepage = 'http://github.com/fazibear/colorize'
11
11
  s.description = 'Ruby String class extension. Adds methods to set text color, background color and, text effects on ruby console and command line output, using ANSI escape sequences.'
12
12
  s.summary = 'Add color methods to String class'
13
13
  s.license = 'GPL-2'
14
14
 
15
15
  s.require_paths = ['lib']
16
-
16
+
17
+ s.add_development_dependency 'rake', '~> 0'
18
+ s.add_development_dependency 'minitest', '~> 0'
19
+ s.add_development_dependency 'codeclimate-test-reporter', '~> 0'
20
+
17
21
  s.files = [
18
22
  'LICENSE',
19
23
  'CHANGELOG',
@@ -19,6 +19,39 @@ module Colorize
19
19
  @disable_colorization = (value || false)
20
20
  end
21
21
 
22
+ #
23
+ # Return array of available colors used by colorize
24
+ #
25
+ def colors
26
+ color_codes.keys
27
+ end
28
+
29
+ #
30
+ # Return array of available modes used by colorize
31
+ #
32
+ def modes
33
+ mode_codes.keys
34
+ end
35
+
36
+ #
37
+ # Display color samples
38
+ #
39
+ def color_samples
40
+ colors.permutation(2).each do |background, color|
41
+ sample_text = "#{color.inspect.rjust(15)} on #{background.inspect.ljust(15)}"
42
+ puts "#{sample_text.colorize(:color => color, :background => background)} #{sample_text}"
43
+ end
44
+ end
45
+
46
+ #
47
+ # Method removed, raise NoMethodError
48
+ #
49
+ def color_matrix(txt = '')
50
+ fail NoMethodError, '#color_matrix method was removed, try #color_samples instead'
51
+ end
52
+
53
+ # private
54
+
22
55
  #
23
56
  # Color codes hash
24
57
  #
@@ -36,13 +69,6 @@ module Colorize
36
69
  }
37
70
  end
38
71
 
39
- #
40
- # Return array of available colors used by colorize
41
- #
42
- def colors
43
- color_codes.keys
44
- end
45
-
46
72
  #
47
73
  # Mode codes hash
48
74
  #
@@ -56,16 +82,9 @@ module Colorize
56
82
  :hide => 8 # Hide text (foreground color would be the same as background)
57
83
  }
58
84
  end
59
-
60
- #
61
- # Return array of available modes used by colorize
62
- #
63
- def modes
64
- mode_codes.keys
65
- end
66
-
85
+
67
86
  #
68
- # Color and on_color methods
87
+ # Generate color and on_color methods
69
88
  #
70
89
  def color_methods
71
90
  colors.each do |key|
@@ -82,7 +101,7 @@ module Colorize
82
101
  end
83
102
 
84
103
  #
85
- # Modes methods
104
+ # Generate modes methods
86
105
  #
87
106
  def modes_methods
88
107
  modes.each do |key|
@@ -93,22 +112,5 @@ module Colorize
93
112
  end
94
113
  end
95
114
  end
96
-
97
- #
98
- # Display color samples
99
- #
100
- def color_samples
101
- colors.permutation(2).each do |background, color|
102
- sample_text = "#{color.inspect.rjust(15)} on #{background.inspect.ljust(15)}"
103
- puts "#{sample_text.colorize(:color => color, :background => background)} #{sample_text}"
104
- end
105
- end
106
-
107
- #
108
- # Method removed, raise NoMethodError
109
- #
110
- def color_matrix(txt = '')
111
- fail NoMethodError, '#color_matrix method was removed, try #color_samples instead'
112
- end
113
115
  end
114
116
  end
@@ -32,7 +32,7 @@ module Colorize
32
32
  #
33
33
  def uncolorize
34
34
  scan_for_colors.inject('') do |str, match|
35
- str << (match[3] || match[4])
35
+ str << match[3]
36
36
  end
37
37
  end
38
38
 
@@ -40,7 +40,9 @@ module Colorize
40
40
  # Return true if string is colorized
41
41
  #
42
42
  def colorized?
43
- scan_for_colors.reject(&:last).any?
43
+ scan_for_colors.inject([]) do |colors, match|
44
+ colors << match.tap(&:pop)
45
+ end.flatten.compact.any?
44
46
  end
45
47
 
46
48
  private
@@ -52,7 +54,6 @@ module Colorize
52
54
  match[0] ||= mode(:default)
53
55
  match[1] ||= color(:default)
54
56
  match[2] ||= background_color(:default)
55
- match[3] ||= match[4]
56
57
  end
57
58
 
58
59
  #
@@ -106,7 +107,18 @@ module Colorize
106
107
  # Scan for colorized string
107
108
  #
108
109
  def scan_for_colors
109
- scan(/\033\[([0-9]+);([0-9]+);([0-9]+)m(.+?)\033\[0m|([^\033]+)/m)
110
+ scan(/\033\[([0-9;]+)m(.+?)\033\[0m|([^\033]+)/m).map do |match|
111
+ split_colors(match)
112
+ end
113
+ end
114
+
115
+ def split_colors(match)
116
+ colors = (match[0] || "").split(';')
117
+ Array.new(4).tap do |array|
118
+ array[0], array[1], array[2] = colors if colors.length == 3
119
+ array[1] = colors if colors.length == 1
120
+ array[3] = match[1] || match[2]
121
+ end
110
122
  end
111
123
 
112
124
  #
@@ -1,7 +1,10 @@
1
- require 'test/unit'
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
4
+ require "minitest/autorun"
2
5
  require File.dirname(__FILE__) + '/../lib/colorize'
3
6
 
4
- class TestColorize < Test::Unit::TestCase
7
+ class TestColorize < Minitest::Test
5
8
  def test_blue_symbol
6
9
  assert_equal 'This is blue'.colorize(:blue),
7
10
  "\e[0;34;49mThis is blue\e[0m"
@@ -72,6 +75,8 @@ class TestColorize < Test::Unit::TestCase
72
75
  assert_equal 'Red'.red.colorized?, true
73
76
  assert_equal 'Blue'.colorized?, false
74
77
  assert_equal 'Green'.blue.green.uncolorize.colorized?, false
78
+ assert_equal ('none' + 'red'.red + 'none' + 'blue'.blue + 'none').colorized?, true
79
+ assert_equal ('none' + 'red'.red + 'none' + 'blue'.blue + 'none').uncolorize.colorized?, false
75
80
  end
76
81
 
77
82
  def test_concatenated_strings_on_green
@@ -94,13 +99,19 @@ class TestColorize < Test::Unit::TestCase
94
99
  "\e[5;34;41mThis is blue\ntext on red\e[0m"
95
100
  end
96
101
 
97
- def test_disable_colorization_with_setter
102
+ def test_disable_colorization_with_=
98
103
  String.disable_colorization = true
99
104
  assert_equal String.disable_colorization, true
100
105
  String.disable_colorization = false
101
106
  end
102
107
 
103
- def test_disable_colorize_with_setter
108
+ def test_disable_colorization_with_method
109
+ String.disable_colorization true
110
+ assert_equal String.disable_colorization, true
111
+ String.disable_colorization false
112
+ end
113
+
114
+ def test_string_disable_colorization_with_=
104
115
  String.disable_colorization = true
105
116
 
106
117
  assert_equal String.disable_colorization, true
@@ -114,7 +125,7 @@ class TestColorize < Test::Unit::TestCase
114
125
  "\e[0;34;49mThis is blue after enabling\e[0m"
115
126
  end
116
127
 
117
- def test_disable_colorize_with_setter
128
+ def test_string_disable_colorization_with_method
118
129
  assert_equal 'This is blue before disabling'.colorize(:blue),
119
130
  "\e[0;34;49mThis is blue before disabling\e[0m"
120
131
 
@@ -129,7 +140,22 @@ class TestColorize < Test::Unit::TestCase
129
140
 
130
141
  assert_equal 'This is blue after enabling'.colorize(:blue),
131
142
  "\e[0;34;49mThis is blue after enabling\e[0m"
143
+ end
132
144
 
145
+ def test_already_colored_string_with_one_value
146
+ assert_equal "\e[31mThis is red\e[0m".red,
147
+ 'This is red'.red
133
148
  end
134
149
 
150
+ def test_color_matrix_method
151
+ assert_raises NoMethodError do
152
+ String.color_matrix
153
+ end
154
+ end
155
+
156
+ def test_color_samples_method
157
+ assert_output do
158
+ String.color_samples
159
+ end
160
+ end
135
161
  end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colorize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
- - fazibear
7
+ - Michał Kalbarczyk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-16 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-04-18 00:00:00.000000000 Z
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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codeclimate-test-reporter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
13
55
  description: Ruby String class extension. Adds methods to set text color, background
14
56
  color and, text effects on ruby console and command line output, using ANSI escape
15
57
  sequences.
@@ -47,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
89
  version: '0'
48
90
  requirements: []
49
91
  rubyforge_project:
50
- rubygems_version: 2.2.2
92
+ rubygems_version: 2.4.5
51
93
  signing_key:
52
94
  specification_version: 4
53
95
  summary: Add color methods to String class