string-irc 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ # https://github.com/travis-ci/travis-ci/wiki/.travis.yml-options
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - ruby-head
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "2.6.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ gem "net-irc", "~> 0.0.9"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.6.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ net-irc (0.0.9)
11
+ rake (0.9.2)
12
+ rcov (0.9.10)
13
+ rspec (2.6.0)
14
+ rspec-core (~> 2.6.0)
15
+ rspec-expectations (~> 2.6.0)
16
+ rspec-mocks (~> 2.6.0)
17
+ rspec-core (2.6.4)
18
+ rspec-expectations (2.6.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.6.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bundler (~> 1.0.0)
27
+ jeweler (~> 1.6.4)
28
+ net-irc (~> 0.0.9)
29
+ rcov
30
+ rspec (= 2.6.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 banyan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # string-irc - Add color codes for mIRC compatible client.
2
+
3
+ [![Build Status](https://secure.travis-ci.org/banyan/string-irc.png)](http://travis-ci.org/banyan/string-irc)
4
+
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
+
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.
26
+
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
+ ---
60
+
61
+ MIT License
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "string-irc"
18
+ gem.homepage = "http://github.com/banyan/string-irc"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{add color codes for mIRC compatible client}
21
+ gem.description = %Q{add color codes for mIRC compatible client}
22
+ gem.email = "ameutau@gmail.com"
23
+ gem.authors = ["banyan"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "string-irc #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,33 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'rubygems'
4
+ require 'net/irc'
5
+ require 'string-irc'
6
+
7
+ class Client < Net::IRC::Client
8
+ def on_rpl_welcome(m)
9
+ post JOIN, opts.channel
10
+ end
11
+
12
+ def on_privmsg(m)
13
+ channel, message = *m
14
+ if message =~ /ping/
15
+ post NOTICE, channel, reply
16
+ end
17
+ end
18
+
19
+ def reply
20
+ si = StringIrc.new('pong')
21
+ si.red.bold.to_s
22
+ end
23
+ end
24
+
25
+ options = {
26
+ :nick => "sibot",
27
+ :user => "sibot",
28
+ :real => "sibot",
29
+ :channel => "",
30
+ :password => "",
31
+ }
32
+ client = Client.new("irc.freenode.net", 6667, options)
33
+ client.start
data/lib/string-irc.rb ADDED
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class StringIrc
4
+
5
+ COLOR_CODE = "\x03" # \u0003
6
+ BOLD = "\x02" # \u0002
7
+ UNDERLINE = "\x1f" # \u001F
8
+ INVERSE = "\x16" # \u0016
9
+ CLEAR = "\x0f" # \u000F
10
+
11
+ COLOR_TABLE = {
12
+ 0 => %w(white),
13
+ 1 => %w(black),
14
+ 2 => %w(blue navy),
15
+ 3 => %w(green),
16
+ 4 => %w(red),
17
+ 5 => %w(brown maroon),
18
+ 6 => %w(purple),
19
+ 7 => %w(orange olive),
20
+ 8 => %w(yellow),
21
+ 9 => %w(light_green lime),
22
+ 10 => %w(teal a_green blue_cyan),
23
+ 11 => %w(light_cyan cyan aqua),
24
+ 12 => %w(light_blue royal),
25
+ 13 => %w(pink light_purple fuchsia),
26
+ 14 => %w(grey),
27
+ 15 => %w(light_grey silver),
28
+ }
29
+
30
+ def initialize(string = nil)
31
+ @string = string
32
+ end
33
+
34
+ color_name_table = {}
35
+
36
+ COLOR_TABLE.each do | code, colors |
37
+ colors.each do |color|
38
+ color_name_table[color] = code
39
+ define_method(color) do | *args |
40
+ 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])}"
43
+ else
44
+ color_code = "#{COLOR_CODE}#{sprintf("%02d", code)}"
45
+ end
46
+ add_code_l(color_code)
47
+ end
48
+ end
49
+ end
50
+
51
+ def bold
52
+ add_code_l BOLD
53
+ end
54
+
55
+ def underline
56
+ add_code_l UNDERLINE
57
+ end
58
+
59
+ def inverse
60
+ add_code_l INVERSE
61
+ end
62
+
63
+ def stringfy
64
+ "#{@string}#{CLEAR}"
65
+ end
66
+
67
+ alias_method :to_s, :stringfy
68
+
69
+ private
70
+ def add_code_l(code)
71
+ @string = "#{code}#{@string}"
72
+ self
73
+ end
74
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'string-irc'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
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" }
14
+ end
15
+
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" }
21
+ end
22
+
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" }
27
+ end
28
+
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
+ end
34
+
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" }
39
+ end
40
+
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
51
+ end
52
+ end
53
+
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" }
69
+ end
70
+
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" }
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{string-irc}
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["banyan"]
12
+ s.date = %q{2011-08-29}
13
+ s.description = %q{add color codes for mIRC compatible client}
14
+ s.email = %q{ameutau@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".travis.yml",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "examples/client.rb",
30
+ "lib/string-irc.rb",
31
+ "spec/spec_helper.rb",
32
+ "spec/string-irc_spec.rb",
33
+ "string-irc.gemspec"
34
+ ]
35
+ s.homepage = %q{http://github.com/banyan/string-irc}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{add color codes for mIRC compatible client}
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<rspec>, ["= 2.6.0"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
49
+ s.add_development_dependency(%q<rcov>, [">= 0"])
50
+ s.add_development_dependency(%q<net-irc>, ["~> 0.0.9"])
51
+ else
52
+ s.add_dependency(%q<rspec>, ["= 2.6.0"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
55
+ s.add_dependency(%q<rcov>, [">= 0"])
56
+ s.add_dependency(%q<net-irc>, ["~> 0.0.9"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rspec>, ["= 2.6.0"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ s.add_dependency(%q<net-irc>, ["~> 0.0.9"])
64
+ end
65
+ end
66
+
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: string-irc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 2
9
+ prerelease: false
10
+ platform: ruby
11
+ authors:
12
+ - banyan
13
+ autorequire: !!null
14
+ bindir: bin
15
+ cert_chain: []
16
+ date: 2011-08-29 00:00:00.000000000 +09:00
17
+ default_executable: !!null
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: rspec
21
+ requirement: &2157485700 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - =
25
+ - !ruby/object:Gem::Version
26
+ version: 2.6.0
27
+ segments:
28
+ - 2
29
+ - 6
30
+ - 0
31
+ type: :development
32
+ prerelease: false
33
+ version_requirements: *2157485700
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ requirement: &2157483020 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: 1.0.0
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *2157483020
49
+ - !ruby/object:Gem::Dependency
50
+ name: jeweler
51
+ requirement: &2157375580 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 1.6.4
57
+ segments:
58
+ - 1
59
+ - 6
60
+ - 4
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: *2157375580
64
+ - !ruby/object:Gem::Dependency
65
+ name: rcov
66
+ requirement: &2157364060 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ segments:
73
+ - 0
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: *2157364060
77
+ - !ruby/object:Gem::Dependency
78
+ name: net-irc
79
+ requirement: &2157346260 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ~>
83
+ - !ruby/object:Gem::Version
84
+ version: 0.0.9
85
+ segments:
86
+ - 0
87
+ - 0
88
+ - 9
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *2157346260
92
+ description: add color codes for mIRC compatible client
93
+ email: ameutau@gmail.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files:
97
+ - LICENSE.txt
98
+ - README.md
99
+ files:
100
+ - .document
101
+ - .rspec
102
+ - .travis.yml
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - LICENSE.txt
106
+ - README.md
107
+ - Rakefile
108
+ - VERSION
109
+ - examples/client.rb
110
+ - lib/string-irc.rb
111
+ - spec/spec_helper.rb
112
+ - spec/string-irc_spec.rb
113
+ - string-irc.gemspec
114
+ has_rdoc: true
115
+ homepage: http://github.com/banyan/string-irc
116
+ licenses:
117
+ - MIT
118
+ post_install_message: !!null
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ segments:
129
+ - 0
130
+ hash: -2918249182448378150
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ segments:
138
+ - 0
139
+ requirements: []
140
+ rubyforge_project: !!null
141
+ rubygems_version: 1.3.7
142
+ signing_key: !!null
143
+ specification_version: 3
144
+ summary: add color codes for mIRC compatible client
145
+ test_files: []