[DRE-commits] [ruby-colorize] 01/01: New upstream version 0.8.1

Michael Crusoe misterc-guest at moszumanska.debian.org
Mon Sep 19 13:02:51 UTC 2016


This is an automated email from the git hooks/post-receive script.

misterc-guest pushed a commit to annotated tag upstream/0.8.1
in repository ruby-colorize.

commit 3e6e586b134ffad84d1585a80cbc8e6ea3db2dd5
Author: Michael R. Crusoe <crusoe at ucdavis.edu>
Date:   Mon Sep 19 02:59:04 2016 -0700

    New upstream version 0.8.1
---
 CHANGELOG                                | 10 ++++
 README.md                                | 60 +++++++++++++++-----
 Rakefile                                 |  7 ++-
 colorize.gemspec                         | 11 ++--
 lib/colorize.rb                          |  2 +-
 lib/colorize/class_methods.rb            | 16 ++++--
 lib/colorize/instance_methods.rb         | 31 +++++-----
 lib/{colorize.rb => colorized_string.rb} | 11 +++-
 metadata.yml                             | 97 --------------------------------
 test/test_colorize.rb                    | 21 ++++---
 10 files changed, 114 insertions(+), 152 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index f6cd806..bf3af18 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,13 @@
+== 0.8.1 / 2016-06-29
+  * fix gemspec bug
+
+== 0.8.0 / 2016-06-27
+	* add ColorizedString class
+	* update README file
+	* add rubocop.yml and follow style
+  * add italic mode
+  * remove interpreter warrnings
+
 == 0.7.7 / 2015-04-19
   * update gems
 
diff --git a/README.md b/README.md
index f1f97d3..dc55167 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,14 @@
 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)
 ========
 
-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.
+Ruby gem for colorizing text using ANSI escape sequences.
+Extends `String` class or add a `ColorizedString` with methods to set text color, background color and text effects.
+
+modes
+-----
+
+* `require 'colorize'` - Extends String class
+* `require 'colorized_string'` - add ColorizedString class
 
 features
 --------
@@ -9,13 +16,24 @@ features
 * change string color
 * change string background
 * change string effect
+* display color samples
+* disable colorization
 
 usage
 -----
 
-Some usage samples:
-
 ```ruby
+require 'colorize'
+
+String.colors                       # return array of all possible colors names
+String.modes                        # return array of all possible modes
+String.color_samples                # displays color samples in all combinations
+String.disable_colorization         # check if colorization is disabled
+String.disable_colorization = false # enable colorization
+String.disable_colorization false   # enable colorization
+String.disable_colorization = true  # disable colorization
+String.disable_colorization true    # disable colorization
+
 puts "This is blue".colorize(:blue)
 puts "This is light blue".colorize(:light_blue)
 puts "This is also blue".colorize(:color => :blue)
@@ -28,17 +46,31 @@ puts "This is blue text on red".blue.on_red.blink
 puts "This is uncolorized".blue.on_red.uncolorize
 ```
 
-Class methods:
-
 ```ruby
-String.colors                       # return array of all possible colors names
-String.modes                        # return array of all possible modes
-String.color_samples                # displays color samples in all combinations
-String.disable_colorization         # check if colorization is disabled
-String.disable_colorization = false # enable colorization
-String.disable_colorization false   # enable colorization
-String.disable_colorization = true  # disable colorization
-String.disable_colorization true    # disable colorization
+require 'colorized_string'
+
+ColorizedString.colors                       # return array of all possible colors names
+ColorizedString.modes                        # return array of all possible modes
+ColorizedString.color_samples                # displays color samples in all combinations
+ColorizedString.disable_colorization         # check if colorization is disabled
+ColorizedString.disable_colorization = false # enable colorization
+ColorizedString.disable_colorization false   # enable colorization
+ColorizedString.disable_colorization = true  # disable colorization
+ColorizedString.disable_colorization true    # disable colorization
+
+puts ColorizedString["This is blue"].colorize(:blue)
+puts ColorizedString["This is light blue"].colorize(:light_blue)
+puts ColorizedString["This is also blue"].colorize(:color => :blue)
+puts ColorizedString["This is light blue with red background"].colorize(:color => :light_blue, :background => :red)
+puts ColorizedString["This is light blue with red background"].colorize(:light_blue ).colorize( :background => :red)
+puts ColorizedString["This is blue text on red"].blue.on_red
+puts ColorizedString["This is red on blue"].colorize(:red).on_blue
+puts ColorizedString["This is red on blue and underline"].colorize(:red).on_blue.underline
+puts ColorizedString["This is blue text on red"].blue.on_red.blink
+puts ColorizedString["This is uncolorized"].blue.on_red.uncolorize
+
+puts ColorizedString.new("This is blue").blue
+puts ColorizedString.new("This is light blue").colorize(:light_blue)
 ```
 
 requirements
@@ -56,7 +88,7 @@ install
 license
 -------
 
-Copyright (C) 2007-2015 Michał Kalbarczyk
+Copyright (C) 2007-2016 Michał Kalbarczyk
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
diff --git a/Rakefile b/Rakefile
index 5814915..e1d05c5 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,4 +5,9 @@ Rake::TestTask.new do |t|
 end
 
 desc 'Run tests'
-task :default => :test
+task :default do
+  ENV['TEST'] = 'test/test_colorize.rb'
+  Rake::Task[:test].execute
+  ENV['TEST'] = 'test/test_colorized_string.rb'
+  Rake::Task[:test].execute
+end
diff --git a/colorize.gemspec b/colorize.gemspec
index 1cb5ec0..de0f968 100644
--- a/colorize.gemspec
+++ b/colorize.gemspec
@@ -1,16 +1,16 @@
 Gem::Specification.new do |s|
   s.name = 'colorize'
-  s.version = '0.7.7'
+  s.version = '0.8.1'
 
   s.authors = ['Michał Kalbarczyk']
   s.email = 'fazibear at gmail.com'
 
-  s.date = Time.now.strftime("%Y-%m-%d")
+  s.date = Time.now.strftime('%Y-%m-%d')
 
   s.homepage = 'http://github.com/fazibear/colorize'
-  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.'
-  s.summary = 'Add color methods to String class'
-  s.license = 'GPL-2'
+  s.description = 'Extends String class or add a ColorizedString with methods to set text color, background color and text effects.'
+  s.summary = 'Ruby gem for colorizing text using ANSI escape sequences.'
+  s.license = 'GPL-2.0'
 
   s.require_paths = ['lib']
 
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
     'Rakefile',
     'colorize.gemspec',
     'lib/colorize.rb',
+    'lib/colorized_string.rb',
     'lib/colorize/class_methods.rb',
     'lib/colorize/instance_methods.rb',
     'test/test_colorize.rb',
diff --git a/lib/colorize.rb b/lib/colorize.rb
index 6b31f46..b10455c 100644
--- a/lib/colorize.rb
+++ b/lib/colorize.rb
@@ -1,7 +1,7 @@
 require File.expand_path('colorize/class_methods', File.dirname(__FILE__))
 require File.expand_path('colorize/instance_methods', File.dirname(__FILE__))
 #
-# Colorize String class extension.
+# String class extension.
 #
 class String
   extend Colorize::ClassMethods
diff --git a/lib/colorize/class_methods.rb b/lib/colorize/class_methods.rb
index 73fd82c..25fc274 100644
--- a/lib/colorize/class_methods.rb
+++ b/lib/colorize/class_methods.rb
@@ -1,12 +1,15 @@
 module Colorize
   module ClassMethods
-
     #
     # Property to disable colorization
     #
     def disable_colorization(value = nil)
       if value.nil?
-        @disable_colorization || false
+        if defined?(@disable_colorization)
+          @disable_colorization || false
+        else
+          false
+        end
       else
         @disable_colorization = (value || false)
       end
@@ -39,17 +42,17 @@ module Colorize
     def color_samples
       colors.permutation(2).each do |background, color|
         sample_text = "#{color.inspect.rjust(15)} on #{background.inspect.ljust(15)}"
-        puts "#{sample_text.colorize(:color => color, :background => background)} #{sample_text}"
+        puts "#{new(sample_text).colorize(:color => color, :background => background)} #{sample_text}"
       end
     end
 
     #
     # Method removed, raise NoMethodError
     #
-    def color_matrix(txt = '')
+    def color_matrix(_ = '')
       fail NoMethodError, '#color_matrix method was removed, try #color_samples instead'
     end
-  
+
     # private
 
     #
@@ -76,13 +79,14 @@ module Colorize
       {
         :default   => 0, # Turn off all attributes
         :bold      => 1, # Set bold mode
+        :italic    => 3, # Set italic mode
         :underline => 4, # Set underline mode
         :blink     => 5, # Set blink mode
         :swap      => 7, # Exchange foreground and background colors
         :hide      => 8  # Hide text (foreground color would be the same as background)
       }
     end
-    
+
     #
     # Generate color and on_color methods
     #
diff --git a/lib/colorize/instance_methods.rb b/lib/colorize/instance_methods.rb
index 6160444..5f7d017 100644
--- a/lib/colorize/instance_methods.rb
+++ b/lib/colorize/instance_methods.rb
@@ -1,6 +1,5 @@
 module Colorize
   module InstanceMethods
-
     #
     # Change color of string
     #
@@ -20,9 +19,9 @@ module Colorize
     def colorize(params)
       return self if self.class.disable_colorization
       require_windows_libs
-      scan_for_colors.inject('') do |str, match|
-        defaults_colors(match)
+      scan_for_colors.inject(self.class.new) do |str, match|
         colors_from_params(match, params)
+        defaults_colors(match)
         str << "\033[#{match[0]};#{match[1]};#{match[2]}m#{match[3]}\033[0m"
       end
     end
@@ -31,7 +30,7 @@ module Colorize
     # Return uncolorized string
     #
     def uncolorize
-      scan_for_colors.inject('') do |str, match|
+      scan_for_colors.inject(self.class.new) do |str, match|
         str << match[3]
       end
     end
@@ -70,8 +69,8 @@ module Colorize
     # Set colors from params hash
     #
     def colors_from_hash(match, hash)
-      match[0] = mode(hash[:mode]) if mode(hash[:mode])
-      match[1] = color(hash[:color]) if color(hash[:color])
+      match[0] = mode(hash[:mode])                   if mode(hash[:mode])
+      match[1] = color(hash[:color])                 if color(hash[:color])
       match[2] = background_color(hash[:background]) if background_color(hash[:background])
     end
 
@@ -113,23 +112,21 @@ module Colorize
     end
 
     def split_colors(match)
-      colors = (match[0] || "").split(';')
-      Array.new(4).tap do |array|
-        array[0], array[1], array[2] = colors if colors.length == 3
-        array[1] = colors                     if colors.length == 1
-        array[3] = match[1] || match[2]
-      end
+      colors = (match[0] || '').split(';')
+      array = Array.new(3)
+      array[0], array[1], array[2] = colors if colors.length == 3
+      array[1] = colors                     if colors.length == 1
+      array[3] = match[1] || match[2]
+      array
     end
 
     #
     # Require windows libs
     #
     def require_windows_libs
-      begin
-        require 'Win32/Console/ANSI' if RUBY_VERSION < "2.0.0" && RUBY_PLATFORM =~ /win32/
-      rescue LoadError
-        raise 'You must gem install win32console to use colorize on Windows'
-      end
+      require 'Win32/Console/ANSI' if RUBY_VERSION < '2.0.0' && RUBY_PLATFORM =~ /win32/
+    rescue LoadError
+      raise 'You must gem install win32console to use colorize on Windows'
     end
   end
 end
diff --git a/lib/colorize.rb b/lib/colorized_string.rb
similarity index 56%
copy from lib/colorize.rb
copy to lib/colorized_string.rb
index 6b31f46..e4ac2ce 100644
--- a/lib/colorize.rb
+++ b/lib/colorized_string.rb
@@ -1,12 +1,19 @@
 require File.expand_path('colorize/class_methods', File.dirname(__FILE__))
 require File.expand_path('colorize/instance_methods', File.dirname(__FILE__))
 #
-# Colorize String class extension.
+# ColorizedString class extension.
 #
-class String
+class ColorizedString < String
   extend Colorize::ClassMethods
   include Colorize::InstanceMethods
 
   color_methods
   modes_methods
+
+  #
+  # Sortcut to create ColorizedString with ColorizedString['test'].
+  #
+  def self.[](string)
+    ColorizedString.new(string)
+  end
 end
diff --git a/metadata.yml b/metadata.yml
deleted file mode 100644
index 2e685ae..0000000
--- a/metadata.yml
+++ /dev/null
@@ -1,97 +0,0 @@
---- !ruby/object:Gem::Specification
-name: colorize
-version: !ruby/object:Gem::Version
-  version: 0.7.7
-platform: ruby
-authors:
-- Michał Kalbarczyk
-autorequire: 
-bindir: bin
-cert_chain: []
-date: 2015-04-19 00:00:00.000000000 Z
-dependencies:
-- !ruby/object:Gem::Dependency
-  name: rake
-  requirement: !ruby/object:Gem::Requirement
-    requirements:
-    - - "~>"
-      - !ruby/object:Gem::Version
-        version: '10.0'
-  type: :development
-  prerelease: false
-  version_requirements: !ruby/object:Gem::Requirement
-    requirements:
-    - - "~>"
-      - !ruby/object:Gem::Version
-        version: '10.0'
-- !ruby/object:Gem::Dependency
-  name: minitest
-  requirement: !ruby/object:Gem::Requirement
-    requirements:
-    - - "~>"
-      - !ruby/object:Gem::Version
-        version: '5.0'
-  type: :development
-  prerelease: false
-  version_requirements: !ruby/object:Gem::Requirement
-    requirements:
-    - - "~>"
-      - !ruby/object:Gem::Version
-        version: '5.0'
-- !ruby/object:Gem::Dependency
-  name: codeclimate-test-reporter
-  requirement: !ruby/object:Gem::Requirement
-    requirements:
-    - - "~>"
-      - !ruby/object:Gem::Version
-        version: '0.4'
-  type: :development
-  prerelease: false
-  version_requirements: !ruby/object:Gem::Requirement
-    requirements:
-    - - "~>"
-      - !ruby/object:Gem::Version
-        version: '0.4'
-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.
-email: fazibear at gmail.com
-executables: []
-extensions: []
-extra_rdoc_files: []
-files:
-- CHANGELOG
-- LICENSE
-- README.md
-- Rakefile
-- colorize.gemspec
-- lib/colorize.rb
-- lib/colorize/class_methods.rb
-- lib/colorize/instance_methods.rb
-- test/test_colorize.rb
-homepage: http://github.com/fazibear/colorize
-licenses:
-- GPL-2
-metadata: {}
-post_install_message: 
-rdoc_options: []
-require_paths:
-- lib
-required_ruby_version: !ruby/object:Gem::Requirement
-  requirements:
-  - - ">="
-    - !ruby/object:Gem::Version
-      version: '0'
-required_rubygems_version: !ruby/object:Gem::Requirement
-  requirements:
-  - - ">="
-    - !ruby/object:Gem::Version
-      version: '0'
-requirements: []
-rubyforge_project: 
-rubygems_version: 2.4.5
-signing_key: 
-specification_version: 4
-summary: Add color methods to String class
-test_files:
-- test/test_colorize.rb
diff --git a/test/test_colorize.rb b/test/test_colorize.rb
index c54861d..b7f1d72 100644
--- a/test/test_colorize.rb
+++ b/test/test_colorize.rb
@@ -1,7 +1,7 @@
-require "codeclimate-test-reporter"
+require 'codeclimate-test-reporter'
 CodeClimate::TestReporter.start
 
-require "minitest/autorun"
+require 'minitest/autorun'
 require File.dirname(__FILE__) + '/../lib/colorize'
 
 class TestColorize < Minitest::Test
@@ -68,25 +68,28 @@ class TestColorize < Minitest::Test
 
   def test_uncolorize
     assert_equal 'This is uncolorized'.blue.on_red.uncolorize,
-                 "This is uncolorized"
+                 'This is uncolorized'
   end
 
   def test_colorized?
     assert_equal 'Red'.red.colorized?, true
     assert_equal 'Blue'.colorized?, false
     assert_equal 'Green'.blue.green.uncolorize.colorized?, false
-    assert_equal ('none' + 'red'.red + 'none' + 'blue'.blue + 'none').colorized?, true
-    assert_equal ('none' + 'red'.red + 'none' + 'blue'.blue + 'none').uncolorize.colorized?, false
+  end
+
+  def test_concatenated__colorize?
+    assert_equal "none #{'red'.red} none #{'blue'.blue} none".colorized?, true
+    assert_equal "none #{'red'.red} none #{'blue'.blue} none".uncolorize.colorized?, false
   end
 
   def test_concatenated_strings_on_green
-    assert_equal ('none' + 'red'.red + 'none' + 'blue'.blue + 'none').on_green,
-                 "\e[0;39;42mnone\e[0m\e[0;31;42mred\e[0m\e[0;39;42mnone\e[0m\e[0;34;42mblue\e[0m\e[0;39;42mnone\e[0m"
+    assert_equal "none #{'red'.red} none #{'blue'.blue} none".on_green,
+                 "\e[0;39;42mnone \e[0m\e[0;31;42mred\e[0m\e[0;39;42m none \e[0m\e[0;34;42mblue\e[0m\e[0;39;42m none\e[0m"
   end
 
   def test_concatenated_strings_uncolorize
-    assert_equal ('none' + 'red'.red + 'none' + 'blue'.blue + 'none').uncolorize,
-                 "nonerednonebluenone"
+    assert_equal "none #{'red'.red} none #{'blue'.blue} none".uncolorize,
+                 'none red none blue none'
   end
 
   def test_frozen_strings

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-colorize.git



More information about the Pkg-ruby-extras-commits mailing list