rugex 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --format d
data/Gemfile CHANGED
@@ -1,13 +1,9 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'thor', '>= 0.14.6'
5
4
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
5
  group :development do
9
- gem "rspec", "~> 2.3.0"
10
- gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.5.2"
12
- gem "rcov", ">= 0"
6
+ gem 'rspec', '~> 2.3.0'
7
+ gem 'bundler', '~> 1.0.9'
8
+ gem 'jeweler', '~> 1.5.2'
13
9
  end
data/Gemfile.lock CHANGED
@@ -8,7 +8,6 @@ GEM
8
8
  git (>= 1.2.5)
9
9
  rake
10
10
  rake (0.8.7)
11
- rcov (0.9.9)
12
11
  rspec (2.3.0)
13
12
  rspec-core (~> 2.3.0)
14
13
  rspec-expectations (~> 2.3.0)
@@ -17,12 +16,13 @@ GEM
17
16
  rspec-expectations (2.3.0)
18
17
  diff-lcs (~> 1.1.2)
19
18
  rspec-mocks (2.3.0)
19
+ thor (0.14.6)
20
20
 
21
21
  PLATFORMS
22
22
  ruby
23
23
 
24
24
  DEPENDENCIES
25
- bundler (~> 1.0.0)
25
+ bundler (~> 1.0.9)
26
26
  jeweler (~> 1.5.2)
27
- rcov
28
27
  rspec (~> 2.3.0)
28
+ thor (>= 0.14.6)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
data/bin/rugex ADDED
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env ruby
2
+ require 'lib/rugex'
@@ -0,0 +1,13 @@
1
+ module Rugex
2
+ module Print
3
+
4
+ private
5
+ def print_colored_text
6
+ colors = {
7
+ :black => "\033[m",
8
+ :blue => "\033[44m"
9
+ }
10
+ @text.gsub(@regex,"#{colors[:blue]}\\&#{colors[:black]}")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ module Rugex
2
+ class Regex
3
+ def self.to_regex(string)
4
+ return Regexp.new(string) if (string =~ /^\/.*\/$/) == nil
5
+ return Regexp.new($1) if (string =~ /^\/(.*)\/$/) != nil
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ require 'lib/rugex/print'
2
+ require 'lib/rugex/regex'
3
+
4
+ class EmptyRegexError < Exception; end
5
+
6
+ module Rugex
7
+ class String
8
+ include Rugex::Print
9
+
10
+ def initialize(text, regex_string)
11
+ raise EmptyRegexError if regex_string.empty?
12
+ @text, @regex = text, Rugex::Regex.to_regex(regex_string)
13
+ @result = (@text =~ @regex) == nil ? '(no matches)' : print_colored_text
14
+ end
15
+
16
+ def to_s; @result; end
17
+ end
18
+ end
data/lib/rugex.rb CHANGED
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ # Rugex - A CLI to test regular expressions on Ruby
4
+ # Author: Lucas Caton - lucascaton at gmail
5
+
6
+ require 'rubygems'
7
+ require 'thor'
8
+ require 'lib/rugex/string'
9
+
10
+ module Rugex
11
+ class Base < Thor
12
+ ARGV.insert(0, 'string') if (ARGV[0] =~ /-./) == nil
13
+
14
+ desc '<text> <regex>', 'show the match text using regular expression'
15
+ def string(text, regex_string)
16
+ puts Rugex::String.new text, regex_string
17
+ end
18
+ end
19
+ end
20
+
21
+ Rugex::Base.start
data/rugex.gemspec CHANGED
@@ -5,13 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rugex}
8
- s.version = "0.0.0"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Lucas Caton"]
12
- s.date = %q{2011-01-27}
12
+ s.date = %q{2011-01-29}
13
+ s.default_executable = %q{rugex}
13
14
  s.description = %q{A CLI to test regular expressions on Ruby}
14
15
  s.email = %q{lucascaton@gmail.com}
16
+ s.executables = ["rugex"]
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE.txt",
17
19
  "README.rdoc"
@@ -25,8 +27,14 @@ Gem::Specification.new do |s|
25
27
  "README.rdoc",
26
28
  "Rakefile",
27
29
  "VERSION",
30
+ "bin/rugex",
28
31
  "lib/rugex.rb",
32
+ "lib/rugex/print.rb",
33
+ "lib/rugex/regex.rb",
34
+ "lib/rugex/string.rb",
29
35
  "rugex.gemspec",
36
+ "spec/lib/regex_spec.rb",
37
+ "spec/lib/string_spec.rb",
30
38
  "spec/rugex_spec.rb",
31
39
  "spec/spec_helper.rb"
32
40
  ]
@@ -36,6 +44,8 @@ Gem::Specification.new do |s|
36
44
  s.rubygems_version = %q{1.4.1}
37
45
  s.summary = %q{A simple tool for testing regular expressions from Ruby using the terminal}
38
46
  s.test_files = [
47
+ "spec/lib/regex_spec.rb",
48
+ "spec/lib/string_spec.rb",
39
49
  "spec/rugex_spec.rb",
40
50
  "spec/spec_helper.rb"
41
51
  ]
@@ -44,21 +54,21 @@ Gem::Specification.new do |s|
44
54
  s.specification_version = 3
45
55
 
46
56
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
+ s.add_runtime_dependency(%q<thor>, [">= 0.14.6"])
47
58
  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
48
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.9"])
49
60
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
50
- s.add_development_dependency(%q<rcov>, [">= 0"])
51
61
  else
62
+ s.add_dependency(%q<thor>, [">= 0.14.6"])
52
63
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
53
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<bundler>, ["~> 1.0.9"])
54
65
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
55
- s.add_dependency(%q<rcov>, [">= 0"])
56
66
  end
57
67
  else
68
+ s.add_dependency(%q<thor>, [">= 0.14.6"])
58
69
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
59
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
70
+ s.add_dependency(%q<bundler>, ["~> 1.0.9"])
60
71
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
61
- s.add_dependency(%q<rcov>, [">= 0"])
62
72
  end
63
73
  end
64
74
 
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Rugex::Regex' do
4
+ describe '.to_regex' do
5
+ context 'receiving a string without slashes' do
6
+ it 'returns a Regexp object' do
7
+ regex = Rugex::Regex.to_regex '\d{4}\d{2}-\d{2}'
8
+ regex.should == /\d{4}\d{2}-\d{2}/
9
+ end
10
+
11
+ it 'returns a empty Regexp object' do
12
+ regex = Rugex::Regex.to_regex ''
13
+ regex.should == //
14
+ end
15
+ end
16
+
17
+ context 'receiving a string with slashes' do
18
+ it 'returns a Regexp object' do
19
+ regex = Rugex::Regex.to_regex '/\d{4}\d{2}-\d{2}/'
20
+ regex.should == /\d{4}\d{2}-\d{2}/
21
+ end
22
+
23
+ it 'returns a empty Regexp object' do
24
+ regex = Rugex::Regex.to_regex '//'
25
+ regex.should == //
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Rugex::String' do
4
+ describe '#to_s' do
5
+ context 'successful' do
6
+ it 'checks text with regular expression' do
7
+ output = Rugex::String.new('John Doe', 'ohn')
8
+ output.to_s.should == "J\e[44mohn\e[m Doe"
9
+ end
10
+
11
+ it 'checks text with other regular expression' do
12
+ output = Rugex::String.new('John Doe', 'John D')
13
+ output.to_s.should == "\e[44mJohn D\e[moe"
14
+ end
15
+ end
16
+
17
+ context 'unsuccessful' do
18
+ it 'checks text with regular expression' do
19
+ output = Rugex::String.new('John Doe', 'Johnny')
20
+ output.to_s.should == "(no matches)"
21
+ end
22
+
23
+ it 'checks text with other regular expression' do
24
+ output = Rugex::String.new('John Doe', 'john doe')
25
+ output.to_s.should == "(no matches)"
26
+ end
27
+
28
+ it 'raise a exception when the regular expression is empty' do
29
+ expect {
30
+ Rugex::String.new('John Doe', '')
31
+ }.to raise_error EmptyRegexError
32
+ end
33
+ end
34
+ end
35
+ end
data/spec/rugex_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require 'spec_helper'
2
2
 
3
- describe 'Rugex' do
3
+ describe 'Rugex::Base' do
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rugex
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 0.0.0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lucas Caton
@@ -15,40 +15,40 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-27 00:00:00 -02:00
19
- default_executable:
18
+ date: 2011-01-29 00:00:00 -02:00
19
+ default_executable: rugex
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  version_requirements: &id001 !ruby/object:Gem::Requirement
23
23
  none: false
24
24
  requirements:
25
- - - ~>
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- hash: 3
27
+ hash: 43
28
28
  segments:
29
- - 2
30
- - 3
31
29
  - 0
32
- version: 2.3.0
30
+ - 14
31
+ - 6
32
+ version: 0.14.6
33
33
  requirement: *id001
34
34
  prerelease: false
35
- name: rspec
36
- type: :development
35
+ name: thor
36
+ type: :runtime
37
37
  - !ruby/object:Gem::Dependency
38
38
  version_requirements: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
42
42
  - !ruby/object:Gem::Version
43
- hash: 23
43
+ hash: 3
44
44
  segments:
45
- - 1
46
- - 0
45
+ - 2
46
+ - 3
47
47
  - 0
48
- version: 1.0.0
48
+ version: 2.3.0
49
49
  requirement: *id002
50
50
  prerelease: false
51
- name: bundler
51
+ name: rspec
52
52
  type: :development
53
53
  - !ruby/object:Gem::Dependency
54
54
  version_requirements: &id003 !ruby/object:Gem::Requirement
@@ -56,34 +56,36 @@ dependencies:
56
56
  requirements:
57
57
  - - ~>
58
58
  - !ruby/object:Gem::Version
59
- hash: 7
59
+ hash: 5
60
60
  segments:
61
61
  - 1
62
- - 5
63
- - 2
64
- version: 1.5.2
62
+ - 0
63
+ - 9
64
+ version: 1.0.9
65
65
  requirement: *id003
66
66
  prerelease: false
67
- name: jeweler
67
+ name: bundler
68
68
  type: :development
69
69
  - !ruby/object:Gem::Dependency
70
70
  version_requirements: &id004 !ruby/object:Gem::Requirement
71
71
  none: false
72
72
  requirements:
73
- - - ">="
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
- hash: 3
75
+ hash: 7
76
76
  segments:
77
- - 0
78
- version: "0"
77
+ - 1
78
+ - 5
79
+ - 2
80
+ version: 1.5.2
79
81
  requirement: *id004
80
82
  prerelease: false
81
- name: rcov
83
+ name: jeweler
82
84
  type: :development
83
85
  description: A CLI to test regular expressions on Ruby
84
86
  email: lucascaton@gmail.com
85
- executables: []
86
-
87
+ executables:
88
+ - rugex
87
89
  extensions: []
88
90
 
89
91
  extra_rdoc_files:
@@ -98,8 +100,14 @@ files:
98
100
  - README.rdoc
99
101
  - Rakefile
100
102
  - VERSION
103
+ - bin/rugex
101
104
  - lib/rugex.rb
105
+ - lib/rugex/print.rb
106
+ - lib/rugex/regex.rb
107
+ - lib/rugex/string.rb
102
108
  - rugex.gemspec
109
+ - spec/lib/regex_spec.rb
110
+ - spec/lib/string_spec.rb
103
111
  - spec/rugex_spec.rb
104
112
  - spec/spec_helper.rb
105
113
  has_rdoc: true
@@ -137,5 +145,7 @@ signing_key:
137
145
  specification_version: 3
138
146
  summary: A simple tool for testing regular expressions from Ruby using the terminal
139
147
  test_files:
148
+ - spec/lib/regex_spec.rb
149
+ - spec/lib/string_spec.rb
140
150
  - spec/rugex_spec.rb
141
151
  - spec/spec_helper.rb