string-irc 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1,2 +1 @@
1
1
  --color
2
- --format documentation
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # https://github.com/travis-ci/travis-ci/wiki/.travis.yml-options
2
2
  rvm:
3
3
  - 1.8.7
4
- - 1.9.2
5
4
  - 1.9.3
5
+ - 2.0.0
6
6
  - ruby-head
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 0.3.0
2
+
3
+ Features:
4
+
5
+ - add original color scheme such as '#rainbow' and '#seven_eleven'
data/Gemfile.lock CHANGED
@@ -1,27 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- string-irc (0.2.1)
5
- net-irc (~> 0.0.9)
4
+ string-irc (0.3.0)
5
+ net-irc (>= 0.0.9)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  diff-lcs (1.1.3)
11
+ json (1.7.7)
11
12
  net-irc (0.0.9)
12
- rspec (2.9.0)
13
- rspec-core (~> 2.9.0)
14
- rspec-expectations (~> 2.9.0)
15
- rspec-mocks (~> 2.9.0)
16
- rspec-core (2.9.0)
17
- rspec-expectations (2.9.1)
13
+ rake (10.0.3)
14
+ rdoc (3.12.1)
15
+ json (~> 1.4)
16
+ rspec (2.12.0)
17
+ rspec-core (~> 2.12.0)
18
+ rspec-expectations (~> 2.12.0)
19
+ rspec-mocks (~> 2.12.0)
20
+ rspec-core (2.12.2)
21
+ rspec-expectations (2.12.1)
18
22
  diff-lcs (~> 1.1.3)
19
- rspec-mocks (2.9.0)
23
+ rspec-mocks (2.12.2)
20
24
 
21
25
  PLATFORMS
22
26
  ruby
23
27
 
24
28
  DEPENDENCIES
25
- bundler (~> 1.1.3)
26
- rspec (~> 2.9.0)
29
+ rake (>= 0.9.2.2)
30
+ rdoc (>= 3.11)
31
+ rspec (>= 2.11.0)
27
32
  string-irc!
data/README.md CHANGED
@@ -1,61 +1,124 @@
1
1
  # string-irc - Add color codes for mIRC compatible client.
2
-
3
2
  [![Build Status](https://secure.travis-ci.org/banyan/string-irc.png)](http://travis-ci.org/banyan/string-irc)
4
- [<img src="https://gemnasium.com/banyan/string-irc.png" />](https://gemnasium.com/banyan/string-irc)
5
- Description
6
- ---
7
-
8
- Port of http://search.cpan.org/~hirose/String-IRC-0.04/ from Perl to Ruby.
9
-
10
- Compatibility
11
- ---
12
-
13
- Tested under Ruby 1.9.2 and Ruby 1.8.7.
14
-
15
- See current status at [Travis CI](http://travis-ci.org/banyan/string-irc).
16
-
17
- Getting Started
18
- ---
19
-
20
- require 'string-irc'
21
3
 
22
- si1 = StringIrc.new('hello')
23
- si1.red.underline
24
- si2 = StringIrc.new('world').yellow('green').bold
25
- msg = "#{si1.to_s} #{si2.to_s}" # You must add #to_s, this is the diffrence from original.
4
+ ## Description
26
5
 
27
- Usage
28
- ---
29
-
30
- si.COLOR([BG_COLOR])
31
-
32
- Add color code and return StringIRC object. BG_COLOR is
33
- optional. Available COLOR and BC_COLOR are as follows.
34
-
35
- white
36
- black
37
- blue navy
38
- green
39
- red
40
- brown maroon
41
- purple
42
- orange olive
43
- yellow
44
- light_green lime
45
- teal a_green blue_cyan
46
- light_cyan cyan aqua
47
- light_blue royal
48
- pink light_purple fuchsia
49
- grey
50
- light_grey silver
51
-
52
- #bold, #underline, #inverse are available method.
53
-
54
- si.bold
55
- si.underline
56
- si.inverse
57
-
58
- Copyright
59
- ---
6
+ Port of http://search.cpan.org/~hirose/String-IRC-0.04/ from Perl to Ruby.
60
7
 
61
- MIT License
8
+ ## Compatibility
9
+
10
+ * Ruby 2.0.0
11
+ * Ruby 1.9.3
12
+ * Ruby 1.8.7
13
+
14
+ ## Getting Started
15
+
16
+ ```
17
+ $ gem install string-irc
18
+ ```
19
+
20
+ ```ruby
21
+ require 'string-irc'
22
+
23
+ si1 = StringIrc.new('hello')
24
+ si1.red.underline.to_s
25
+ si2 = StringIrc.new('world').yellow('green').bold.to_s
26
+ message = "#{si1} #{si2}"
27
+ p message # => "\u001F\u000304hello\u000F \u0002\u000308,03world\u000F"
28
+ ```
29
+
30
+ ### Caveats
31
+
32
+ * To strigfy StringIrc instance, you have to add #to_s method. This API is diffrence from original one.
33
+
34
+ ### Try with IRC
35
+
36
+ * There is example code in `example` directory, try with IRC how looks it.
37
+
38
+ ## Usage
39
+
40
+ ```
41
+ string_irc_instance.COLOR([BG_COLOR])
42
+ ```
43
+
44
+ * Color scheme
45
+
46
+ <table>
47
+ <tr>
48
+ <th>foreground, and background</th>
49
+ </tr>
50
+ <tr>
51
+ <td>white</td>
52
+ </tr>
53
+ <tr>
54
+ <td>black</td>
55
+ </tr>
56
+ <tr>
57
+ <td>blue, navy</td>
58
+ </tr>
59
+ <tr>
60
+ <td>green</td>
61
+ </tr>
62
+ <tr>
63
+ <td>red</td>
64
+ </tr>
65
+ <tr>
66
+ <td>brown, maroon</td>
67
+ </tr>
68
+ <tr>
69
+ <td>purple</td>
70
+ </tr>
71
+ <tr>
72
+ <td>orange, olive</td>
73
+ </tr>
74
+ <tr>
75
+ <td>yellow</td>
76
+ </tr>
77
+ <tr>
78
+ <td>light_green, lime</td>
79
+ </tr>
80
+ <tr>
81
+ <td>teal, a_green, blue_cyan</td>
82
+ </tr>
83
+ <tr>
84
+ <td>light_cyan, cyan, aqua</td>
85
+ </tr>
86
+ <tr>
87
+ <td>light_blue, royal</td>
88
+ </tr>
89
+ <tr>
90
+ <td>pink, light_purple, fuchsia</td>
91
+ </tr>
92
+ <tr>
93
+ <td>grey</td>
94
+ </tr>
95
+ <tr>
96
+ <td>light_grey, silver</td>
97
+ </tr>
98
+ </table>
99
+
100
+ * Decorate method
101
+
102
+ ```
103
+ #bold
104
+ #underline
105
+ #inverse
106
+ ```
107
+
108
+ * Original color scheme (currently it's only available as foreground color)
109
+
110
+ <table>
111
+ <tr>
112
+ <th>foreground only</th>
113
+ </tr>
114
+ <tr>
115
+ <td>rainbow</td>
116
+ </tr>
117
+ <tr>
118
+ <td>seven_eleven</td>
119
+ </tr>
120
+ </table>
121
+
122
+ ## Copyright
123
+
124
+ Copyright (c) 2012 Kohei Hasegawa. See LICENSE for [details](http://banyan.mit-license.org/).
File without changes
data/lib/string-irc.rb CHANGED
@@ -1,7 +1,6 @@
1
- # -*- coding: utf-8 -*-
1
+ # coding: utf-8
2
2
 
3
3
  class StringIrc
4
-
5
4
  COLOR_CODE = "\x03" # \u0003
6
5
  BOLD = "\x02" # \u0002
7
6
  UNDERLINE = "\x1f" # \u001F
@@ -27,27 +26,50 @@ class StringIrc
27
26
  15 => %w(light_grey silver),
28
27
  }
29
28
 
29
+ ORIGINAL_COLOR_SCHEME = {
30
+ "rainbow" => %w(red orange yellow green blue light_blue purple), # order is referred: http://ja.wikipedia.org/wiki/%E8%99%B9
31
+ "seven_eleven" => %w(orange green red)
32
+ }
33
+
30
34
  def initialize(string = nil)
31
35
  @string = string
32
36
  end
33
37
 
34
- color_name_table = {}
38
+ @@color_name_table = {}
35
39
 
36
- COLOR_TABLE.each do | code, colors |
40
+ COLOR_TABLE.each do |code, colors|
37
41
  colors.each do |color|
38
- color_name_table[color] = code
39
- define_method(color) do | *args |
42
+ @@color_name_table[color] = code
43
+ define_method(color) do |*args|
40
44
  bg_color = args.first || nil
41
- if (!!bg_color and color_name_table.include?(bg_color))
42
- color_code = "#{COLOR_CODE}#{sprintf("%02d,%02d", code, color_name_table[bg_color])}"
45
+ raise ArgumentError, "`#{bg_color}' is not allowed to use as background color" if ORIGINAL_COLOR_SCHEME.include?(bg_color)
46
+ if bg_color && @@color_name_table.include?(bg_color)
47
+ color_code = "#{COLOR_CODE}#{"%02d,%02d" % [code, @@color_name_table[bg_color]]}"
43
48
  else
44
- color_code = "#{COLOR_CODE}#{sprintf("%02d", code)}"
49
+ color_code = "#{COLOR_CODE}#{"%02d" % code}"
45
50
  end
46
51
  add_code_l(color_code)
47
52
  end
48
53
  end
49
54
  end
50
55
 
56
+ ORIGINAL_COLOR_SCHEME.each do |key, order|
57
+ define_method(key) do |*args|
58
+ index = 0
59
+ bg_color = args.first || nil
60
+ @string = @string.each_char.map { |char|
61
+ order = index % ORIGINAL_COLOR_SCHEME[key].size
62
+ index += 1
63
+ if bg_color && @@color_name_table.include?(bg_color)
64
+ "#{COLOR_CODE}#{"%02d,%02d" % [@@color_name_table[ORIGINAL_COLOR_SCHEME[key][order]], @@color_name_table[bg_color]]}#{char}"
65
+ else
66
+ "#{COLOR_CODE}#{"%02d" % @@color_name_table[ORIGINAL_COLOR_SCHEME[key][order]]}#{char}"
67
+ end
68
+ }.join
69
+ self
70
+ end
71
+ end
72
+
51
73
  def bold
52
74
  add_code_l BOLD
53
75
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
3
4
  require 'rspec'
4
5
  require 'string-irc'
5
6
 
@@ -8,5 +9,4 @@ require 'string-irc'
8
9
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
10
 
10
11
  RSpec.configure do |config|
11
-
12
12
  end
@@ -1,77 +1,58 @@
1
- # encoding: utf-8
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
3
 
4
4
  describe StringIrc do
5
- share_examples_for 'when it first created' do
6
- specify { should be_an_instance_of StringIrc }
7
- end
8
-
9
- context 'with an argument "hello"' do
10
- subject { StringIrc.new('hello') }
11
-
12
- it_should_behave_like 'when it first created' do
13
- its(:to_s) { should == "hello\x0f" }
5
+ subject { StringIrc.new('hello') }
6
+
7
+ describe '#to_s' do
8
+ context 'when only foreground color passed in' do
9
+ StringIrc::COLOR_TABLE.each do |color, codes|
10
+ codes.each do |code|
11
+ context "foreground color: #{code}" do
12
+ it { expect(subject.send(code).to_s).to eq("\x03#{ "%02d" % color }hello\x0f") }
13
+ end
14
+ end
15
+ end
14
16
  end
15
17
 
16
- context "single color" do
17
- its("red.to_s") { should == "\x0304hello\x0f" }
18
- its("blue.to_s") { should == "\x0302hello\x0f" }
19
- its("blue_cyan.to_s") { should == "\x0310hello\x0f" }
20
- its("light_purple.to_s") { should == "\x0313hello\x0f" }
18
+ context 'when foreground color and background color are passed in' do
19
+ StringIrc::COLOR_TABLE.each do |color, codes|
20
+ codes.each do |code|
21
+ context "foreground color and background color: #{code}" do
22
+ it { expect(subject.send(code, code).to_s).to eq("\x03#{ "%02d" % color },#{ "%02d" % color }hello\x0f") }
23
+ end
24
+ end
25
+ end
21
26
  end
22
27
 
23
- context "decoration" do
24
- its("bold.to_s") { should == "\x02hello\x0f" }
25
- its("underline.to_s") { should == "\x1fhello\x0f" }
26
- its("inverse.to_s") { should == "\x16hello\x0f" }
28
+ context 'when colors are not passed in' do
29
+ it { expect(subject.to_s).to eq("hello\x0f") }
27
30
  end
31
+ end
28
32
 
29
- context "complex" do
30
- its("bold.yellow.to_s") { should == "\x0308\x02hello\x0f" }
31
- its("bold.yellow.underline.to_s") { should == "\x1f\x0308\x02hello\x0f" }
32
- its("bold.yellow.underline.inverse.to_s") { should == "\x16\x1f\x0308\x02hello\x0f" }
33
+ context "when decorating method passed in" do
34
+ describe '#bold' do
35
+ it { expect(subject.bold.to_s).to eq("\x02hello\x0f") }
33
36
  end
34
37
 
35
- context "complex" do
36
- its("bold.yellow.to_s") { should == "\x0308\x02hello\x0f" }
37
- its("bold.yellow.underline.to_s") { should == "\x1f\x0308\x02hello\x0f" }
38
- its("bold.yellow.underline.inverse.to_s") { should == "\x16\x1f\x0308\x02hello\x0f" }
38
+ describe '#underline' do
39
+ it { expect(subject.underline.to_s).to eq("\x1fhello\x0f") }
39
40
  end
40
41
 
41
- context "bg-color" do
42
- describe 'yellow("red").to_s' do
43
- it { subject.yellow("red").to_s.should == "\x0308,04hello\x0f" }
44
- end
45
- describe 'red("yellow").to_s' do
46
- it { subject.red("yellow").to_s.should == "\x0304,08hello\x0f" }
47
- end
48
- describe 'red("cyan").to_s' do
49
- it { subject.red("cyan").to_s.should == "\x0304,11hello\x0f" }
50
- end
42
+ describe '#inverse' do
43
+ it { expect(subject.inverse.to_s).to eq("\x16hello\x0f") }
51
44
  end
52
45
  end
53
46
 
54
- context "without an argument" do
55
- subject { StringIrc.new }
56
-
57
- it_should_behave_like "when it first created" do
58
- its(:to_s) { should == "\x0f" }
59
- end
60
-
61
- context "single color" do
62
- its("red.to_s") { should == "\x0304\x0f" }
63
- end
64
-
65
- context "decoration" do
66
- its("bold.to_s") { should == "\x02\x0f" }
67
- its("underline.to_s") { should == "\x1f\x0f" }
68
- its("inverse.to_s") { should == "\x16\x0f" }
47
+ context "when original color scheme method passed in" do
48
+ describe '#rainbow' do
49
+ it { expect(subject.rainbow.to_s).to eq("\x0304h\x0307e\x0308l\x0303l\x0302o\x0f") }
50
+ it { expect(subject.rainbow("black").to_s).to eq("\x0304,01h\x0307,01e\x0308,01l\x0303,01l\x0302,01o\x0f") }
69
51
  end
70
52
 
71
- context "complex" do
72
- its("bold.yellow.to_s") { should == "\x0308\x02\x0f" }
73
- its("bold.yellow.underline.to_s") { should == "\x1f\x0308\x02\x0f" }
74
- its("bold.yellow.underline.inverse.to_s") { should == "\x16\x1f\x0308\x02\x0f" }
53
+ describe '#seven_eleven' do
54
+ it { expect(subject.seven_eleven.to_s).to eq("\x0307h\x0303e\x0304l\x0307l\x0303o\x0f") }
55
+ it { expect(subject.seven_eleven("black").to_s).to eq("\x0307,01h\x0303,01e\x0304,01l\x0307,01l\x0303,01o\x0f") }
75
56
  end
76
57
  end
77
58
  end
data/string-irc.gemspec CHANGED
@@ -13,12 +13,11 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
14
  gem.name = "string-irc"
15
15
  gem.require_paths = ["lib"]
16
- gem.version = "0.2.3"
16
+ gem.version = "0.3.0"
17
17
 
18
18
  # dependencies
19
- gem.add_development_dependency "rspec", "~> 2.9.0"
20
- gem.add_development_dependency "bundler", "~> 1.1.3"
21
- gem.add_development_dependency 'rake', '~> 0.9.2.2' # need for Travis CI
22
- gem.add_development_dependency 'rdoc', '~> 3.11' # need for Travis CI
23
- gem.add_runtime_dependency "net-irc", "~> 0.0.9"
19
+ gem.add_runtime_dependency "net-irc", ">= 0.0.9"
20
+ gem.add_development_dependency "rspec", ">= 2.11.0"
21
+ gem.add_development_dependency 'rake', '>= 0.9.2.2' # need for Travis CI
22
+ gem.add_development_dependency 'rdoc', '>= 3.11' # need for Travis CI
24
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string-irc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,60 +12,69 @@ cert_chain: []
12
12
  date: 2012-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rspec
16
- requirement: &70325208808020 !ruby/object:Gem::Requirement
15
+ name: net-irc
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 2.9.0
22
- type: :development
21
+ version: 0.0.9
22
+ type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70325208808020
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.9
25
30
  - !ruby/object:Gem::Dependency
26
- name: bundler
27
- requirement: &70325207455720 !ruby/object:Gem::Requirement
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
- - - ~>
35
+ - - ! '>='
31
36
  - !ruby/object:Gem::Version
32
- version: 1.1.3
37
+ version: 2.11.0
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70325207455720
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.11.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rake
38
- requirement: &70325207449120 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
- - - ~>
51
+ - - ! '>='
42
52
  - !ruby/object:Gem::Version
43
53
  version: 0.9.2.2
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70325207449120
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2.2
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rdoc
49
- requirement: &70325208828460 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
- - - ~>
67
+ - - ! '>='
53
68
  - !ruby/object:Gem::Version
54
69
  version: '3.11'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70325208828460
58
- - !ruby/object:Gem::Dependency
59
- name: net-irc
60
- requirement: &70325208828000 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
61
73
  none: false
62
74
  requirements:
63
- - - ~>
75
+ - - ! '>='
64
76
  - !ruby/object:Gem::Version
65
- version: 0.0.9
66
- type: :runtime
67
- prerelease: false
68
- version_requirements: *70325208828000
77
+ version: '3.11'
69
78
  description: add color codes for mIRC compatible client
70
79
  email:
71
80
  - ameutau@gmail.com
@@ -76,13 +85,13 @@ files:
76
85
  - .gitignore
77
86
  - .rspec
78
87
  - .travis.yml
88
+ - CHANGELOG.md
79
89
  - Gemfile
80
90
  - Gemfile.lock
81
91
  - LICENSE
82
92
  - README.md
83
93
  - Rakefile
84
- - VERSION
85
- - examples/client.rb
94
+ - example/client.rb
86
95
  - lib/string-irc.rb
87
96
  - spec/spec_helper.rb
88
97
  - spec/string-irc_spec.rb
@@ -100,19 +109,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
109
  - - ! '>='
101
110
  - !ruby/object:Gem::Version
102
111
  version: '0'
112
+ segments:
113
+ - 0
114
+ hash: 131660736276985680
103
115
  required_rubygems_version: !ruby/object:Gem::Requirement
104
116
  none: false
105
117
  requirements:
106
118
  - - ! '>='
107
119
  - !ruby/object:Gem::Version
108
120
  version: '0'
121
+ segments:
122
+ - 0
123
+ hash: 131660736276985680
109
124
  requirements: []
110
125
  rubyforge_project:
111
- rubygems_version: 1.8.11
126
+ rubygems_version: 1.8.23
112
127
  signing_key:
113
128
  specification_version: 3
114
129
  summary: add color codes for mIRC compatible client
115
130
  test_files:
116
131
  - spec/spec_helper.rb
117
132
  - spec/string-irc_spec.rb
118
- has_rdoc:
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.3