rugex 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,4 +4,5 @@ group :development do
4
4
  gem 'rspec', '~> 2.3.0'
5
5
  gem 'bundler', '~> 1.0.9'
6
6
  gem 'jeweler', '~> 1.5.2'
7
+ gem 'aruba'
7
8
  end
data/Gemfile.lock CHANGED
@@ -1,12 +1,30 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ aruba (0.3.2)
5
+ childprocess (~> 0.1.6)
6
+ cucumber (~> 0.10.0)
7
+ rspec (~> 2.3.0)
8
+ builder (3.0.0)
9
+ childprocess (0.1.6)
10
+ ffi (~> 0.6.3)
11
+ cucumber (0.10.0)
12
+ builder (>= 2.1.2)
13
+ diff-lcs (~> 1.1.2)
14
+ gherkin (~> 2.3.2)
15
+ json (~> 1.4.6)
16
+ term-ansicolor (~> 1.0.5)
4
17
  diff-lcs (1.1.2)
18
+ ffi (0.6.3)
19
+ rake (>= 0.8.7)
20
+ gherkin (2.3.3)
21
+ json (~> 1.4.6)
5
22
  git (1.2.5)
6
23
  jeweler (1.5.2)
7
24
  bundler (~> 1.0.0)
8
25
  git (>= 1.2.5)
9
26
  rake
27
+ json (1.4.6)
10
28
  rake (0.8.7)
11
29
  rspec (2.3.0)
12
30
  rspec-core (~> 2.3.0)
@@ -16,11 +34,13 @@ GEM
16
34
  rspec-expectations (2.3.0)
17
35
  diff-lcs (~> 1.1.2)
18
36
  rspec-mocks (2.3.0)
37
+ term-ansicolor (1.0.5)
19
38
 
20
39
  PLATFORMS
21
40
  ruby
22
41
 
23
42
  DEPENDENCIES
43
+ aruba
24
44
  bundler (~> 1.0.9)
25
45
  jeweler (~> 1.5.2)
26
46
  rspec (~> 2.3.0)
data/README.textile CHANGED
@@ -28,11 +28,15 @@ h2. For example:
28
28
  <pre><code>rugex aquarius 'a[qr]'</code></pre>
29
29
  => *aq* u *ar* ius
30
30
 
31
+ h2. Using files:
32
+
33
+ <pre><code>rugex -f [file path] [regex]</code></pre>
34
+
31
35
  h1. TODO
32
36
 
33
- * File Suport
34
37
  * Regex Options (i, m, x, o)
35
38
  * It does not work in Windows OS.
39
+ * Show matches groups separately
36
40
 
37
41
  h1. Contributing to Lucas Caton
38
42
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.2.0
data/bin/rugex CHANGED
@@ -7,8 +7,9 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
7
7
 
8
8
  require 'optparse'
9
9
  require 'rugex/string'
10
+ require 'rugex/file'
10
11
 
11
- options = {}
12
+ options = {:file => false}
12
13
 
13
14
  optparse = OptionParser.new do |opts|
14
15
  opts.banner = "Usage:\n\nrugex <text> <regex>\n\nYou can use flags as such:"
@@ -18,6 +19,10 @@ optparse = OptionParser.new do |opts|
18
19
  exit
19
20
  end
20
21
 
22
+ opts.on('-f', '--file', 'Receives a file as input') do
23
+ options[:file] = true
24
+ end
25
+
21
26
  if ARGV.size < 2
22
27
  puts opts
23
28
  exit
@@ -31,6 +36,8 @@ rescue OptionParser::InvalidOption => e
31
36
  exit
32
37
  end
33
38
 
34
- text = ARGV[0]
35
- regex_string = ARGV[1]
36
- puts Rugex::String.new text, regex_string
39
+ if options[:file] == true
40
+ puts Rugex::File.new ARGV[0], ARGV[1]
41
+ else
42
+ puts Rugex::String.new ARGV[0], ARGV[1]
43
+ end
@@ -0,0 +1,2 @@
1
+ @file
2
+ Feature: Running the executable using a file
File without changes
@@ -0,0 +1,16 @@
1
+ @string
2
+ Feature: Running the executable using string
3
+
4
+ Scenario Outline: Show "usage" if the user typed a invalid sintax
5
+ When I run "<input>"
6
+ Then the output should contain "Usage:\n\nrugex <text> <regex>\n\nYou can use flags as such:"
7
+ Examples:
8
+ | input |
9
+ | rugex |
10
+ | rugex -h |
11
+ | rugex --help |
12
+ | rugex only_one_argument |
13
+
14
+ Scenario: Show invalid option message if the user typed a invalid flag
15
+ When I run "rugex -r regex"
16
+ Then the output should contain "invalid option: -r"
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
data/lib/exceptions.rb ADDED
@@ -0,0 +1,5 @@
1
+ class EmptyRegexError < Exception
2
+ def initialize
3
+ super 'The regex param should not be blank.'
4
+ end
5
+ end
data/lib/rugex/file.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'rugex/print'
2
+
3
+ module Rugex
4
+ class File
5
+ include Rugex::Print
6
+
7
+ def initialize(file_path, regex_string)
8
+ raise EmptyRegexError if regex_string.empty?
9
+
10
+ @regex = Regexp.new(regex_string)
11
+
12
+ file = ::File.open(file_path)
13
+ @result = file.lines.inject '' do |colored_text, line|
14
+ @text = line
15
+ colored_text << colorize_text
16
+ end
17
+ file.close
18
+ end
19
+
20
+ def to_s; @result; end
21
+ end
22
+ end
data/lib/rugex/print.rb CHANGED
@@ -2,7 +2,7 @@ module Rugex
2
2
  module Print
3
3
 
4
4
  private
5
- def print_colored_text
5
+ def colorize_text
6
6
  colors = {
7
7
  :white => "\033[0;37m",
8
8
  :red => "\033[0;31m\033[4m"
data/lib/rugex/string.rb CHANGED
@@ -1,11 +1,4 @@
1
1
  require 'rugex/print'
2
- require 'rugex/regex'
3
-
4
- class EmptyRegexError < Exception
5
- def initialize
6
- super 'The regex param should not be blank.'
7
- end
8
- end
9
2
 
10
3
  module Rugex
11
4
  class String
@@ -13,8 +6,9 @@ module Rugex
13
6
 
14
7
  def initialize(text, regex_string)
15
8
  raise EmptyRegexError if regex_string.empty?
9
+
16
10
  @text, @regex = text, Regexp.new(regex_string)
17
- @result = (@text =~ @regex) == nil ? '(no matches)' : print_colored_text
11
+ @result = (@text =~ @regex) == nil ? '(no matches)' : colorize_text
18
12
  end
19
13
 
20
14
  def to_s; @result; end
data/rugex.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rugex}
8
- s.version = "0.1.5"
8
+ s.version = "0.2.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"]
@@ -28,9 +28,17 @@ Gem::Specification.new do |s|
28
28
  "Rakefile",
29
29
  "VERSION",
30
30
  "bin/rugex",
31
+ "features/file.feature",
32
+ "features/step_definitions/command_line_steps.rb",
33
+ "features/string.feature",
34
+ "features/support/env.rb",
35
+ "lib/exceptions.rb",
36
+ "lib/rugex/file.rb",
31
37
  "lib/rugex/print.rb",
32
38
  "lib/rugex/string.rb",
33
39
  "rugex.gemspec",
40
+ "spec/fixtures/file.txt",
41
+ "spec/lib/file_spec.rb",
34
42
  "spec/lib/string_spec.rb",
35
43
  "spec/spec_helper.rb"
36
44
  ]
@@ -40,6 +48,7 @@ Gem::Specification.new do |s|
40
48
  s.rubygems_version = %q{1.4.1}
41
49
  s.summary = %q{A simple tool for testing regular expressions from Ruby using the terminal}
42
50
  s.test_files = [
51
+ "spec/lib/file_spec.rb",
43
52
  "spec/lib/string_spec.rb",
44
53
  "spec/spec_helper.rb"
45
54
  ]
@@ -51,15 +60,18 @@ Gem::Specification.new do |s|
51
60
  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
52
61
  s.add_development_dependency(%q<bundler>, ["~> 1.0.9"])
53
62
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
63
+ s.add_development_dependency(%q<aruba>, [">= 0"])
54
64
  else
55
65
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
56
66
  s.add_dependency(%q<bundler>, ["~> 1.0.9"])
57
67
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
68
+ s.add_dependency(%q<aruba>, [">= 0"])
58
69
  end
59
70
  else
60
71
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
61
72
  s.add_dependency(%q<bundler>, ["~> 1.0.9"])
62
73
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
74
+ s.add_dependency(%q<aruba>, [">= 0"])
63
75
  end
64
76
  end
65
77
 
@@ -0,0 +1,2 @@
1
+ Lorem ipsum dolor sit amet,
2
+ consectetur magna aliqua.
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Rugex::File' do
4
+ describe '#to_s' do
5
+ it 'checks file with regular expression' do
6
+ output = Rugex::File.new('spec/fixtures/file.txt', 'a[gm].a?')
7
+ output.to_s.should == "Lorem ipsum dolor sit \e[0;31m\e[4mame\e[0;37mt,\nconsectetur m\e[0;31m\e[4magna\e[0;37m aliqua.\n"
8
+ end
9
+ end
10
+ 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: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 5
10
- version: 0.1.5
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lucas Caton
@@ -66,6 +66,20 @@ dependencies:
66
66
  prerelease: false
67
67
  name: jeweler
68
68
  type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirement: *id004
80
+ prerelease: false
81
+ name: aruba
82
+ type: :development
69
83
  description: A CLI to test regular expressions on Ruby
70
84
  email: lucascaton@gmail.com
71
85
  executables:
@@ -85,9 +99,17 @@ files:
85
99
  - Rakefile
86
100
  - VERSION
87
101
  - bin/rugex
102
+ - features/file.feature
103
+ - features/step_definitions/command_line_steps.rb
104
+ - features/string.feature
105
+ - features/support/env.rb
106
+ - lib/exceptions.rb
107
+ - lib/rugex/file.rb
88
108
  - lib/rugex/print.rb
89
109
  - lib/rugex/string.rb
90
110
  - rugex.gemspec
111
+ - spec/fixtures/file.txt
112
+ - spec/lib/file_spec.rb
91
113
  - spec/lib/string_spec.rb
92
114
  - spec/spec_helper.rb
93
115
  has_rdoc: true
@@ -125,5 +147,6 @@ signing_key:
125
147
  specification_version: 3
126
148
  summary: A simple tool for testing regular expressions from Ruby using the terminal
127
149
  test_files:
150
+ - spec/lib/file_spec.rb
128
151
  - spec/lib/string_spec.rb
129
152
  - spec/spec_helper.rb