ruby-grep 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +25 -0
- data/Gemfile.lock +74 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +19 -0
- data/Rakefile +37 -0
- data/VERSION +1 -0
- data/bin/ruby-grep +12 -0
- data/lib/ruby-grep.rb +6 -0
- data/lib/ruby-grep/directory.rb +19 -0
- data/lib/ruby-grep/expression.rb +46 -0
- data/lib/ruby-grep/file.rb +43 -0
- data/lib/ruby-grep/line.rb +36 -0
- data/ruby-grep screenshot.png +0 -0
- data/ruby-grep.gemspec +78 -0
- data/spec/directory_spec.rb +37 -0
- data/spec/expression_spec.rb +26 -0
- data/spec/file_spec.rb +30 -0
- data/spec/fixtures/test_file.txt +7 -0
- data/spec/line_spec.rb +9 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/test_data.rb +1 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7d1e878e9e5f3c65209c77d4f24b2691ed938d75
|
4
|
+
data.tar.gz: c20c6c2dd8e1274202a665d6b5ffa318f314bea4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9bc17924355008eefc9b619bfe630707db131eb922562d34bd55c975963cc044ae507b78bff16eff860f093a1a4a33aeecca54b4e11f59b38bd1de7981a4fcda
|
7
|
+
data.tar.gz: e5aee446d946a9c9da65b5dcd41b59abe020ed052b9ef350a2389ffb6502b7a82052bfab1b1c744a40bed86b810f5d129fcee8edcecdc35539f95082ea2d37a4
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,25 @@
|
|
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
|
+
if RUBY_VERSION =~ /1.9/
|
9
|
+
Encoding.default_external = Encoding::UTF_8
|
10
|
+
Encoding.default_internal = Encoding::UTF_8
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
group :development do
|
15
|
+
gem "rdoc"
|
16
|
+
gem "bundler"
|
17
|
+
gem "jeweler"
|
18
|
+
gem "rspec"
|
19
|
+
end
|
20
|
+
|
21
|
+
gem "colorize"
|
22
|
+
|
23
|
+
group :development, :test do
|
24
|
+
gem "debugger"
|
25
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.5)
|
5
|
+
builder (3.2.2)
|
6
|
+
colorize (0.5.8)
|
7
|
+
columnize (0.3.6)
|
8
|
+
debugger (1.3.1)
|
9
|
+
columnize (>= 0.3.1)
|
10
|
+
debugger-linecache (~> 1.1.1)
|
11
|
+
debugger-ruby_core_source (~> 1.1.8)
|
12
|
+
debugger-linecache (1.1.2)
|
13
|
+
debugger-ruby_core_source (>= 1.1.1)
|
14
|
+
debugger-ruby_core_source (1.1.8)
|
15
|
+
diff-lcs (1.2.4)
|
16
|
+
faraday (0.8.7)
|
17
|
+
multipart-post (~> 1.1)
|
18
|
+
git (1.2.5)
|
19
|
+
github_api (0.10.1)
|
20
|
+
addressable
|
21
|
+
faraday (~> 0.8.1)
|
22
|
+
hashie (>= 1.2)
|
23
|
+
multi_json (~> 1.4)
|
24
|
+
nokogiri (~> 1.5.2)
|
25
|
+
oauth2
|
26
|
+
hashie (2.0.5)
|
27
|
+
highline (1.6.19)
|
28
|
+
httpauth (0.2.0)
|
29
|
+
jeweler (1.8.5)
|
30
|
+
builder
|
31
|
+
bundler (~> 1.0)
|
32
|
+
git (>= 1.2.5)
|
33
|
+
github_api (>= 0.8.1)
|
34
|
+
highline (>= 1.6.15)
|
35
|
+
nokogiri (= 1.5.10)
|
36
|
+
rake
|
37
|
+
rdoc
|
38
|
+
json (1.8.0)
|
39
|
+
jwt (0.1.8)
|
40
|
+
multi_json (>= 1.5)
|
41
|
+
multi_json (1.7.7)
|
42
|
+
multi_xml (0.5.4)
|
43
|
+
multipart-post (1.2.0)
|
44
|
+
nokogiri (1.5.10)
|
45
|
+
oauth2 (0.9.2)
|
46
|
+
faraday (~> 0.8)
|
47
|
+
httpauth (~> 0.2)
|
48
|
+
jwt (~> 0.1.4)
|
49
|
+
multi_json (~> 1.0)
|
50
|
+
multi_xml (~> 0.5)
|
51
|
+
rack (~> 1.2)
|
52
|
+
rack (1.5.2)
|
53
|
+
rake (10.1.0)
|
54
|
+
rdoc (4.0.1)
|
55
|
+
json (~> 1.4)
|
56
|
+
rspec (2.13.0)
|
57
|
+
rspec-core (~> 2.13.0)
|
58
|
+
rspec-expectations (~> 2.13.0)
|
59
|
+
rspec-mocks (~> 2.13.0)
|
60
|
+
rspec-core (2.13.1)
|
61
|
+
rspec-expectations (2.13.0)
|
62
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
63
|
+
rspec-mocks (2.13.1)
|
64
|
+
|
65
|
+
PLATFORMS
|
66
|
+
ruby
|
67
|
+
|
68
|
+
DEPENDENCIES
|
69
|
+
bundler
|
70
|
+
colorize
|
71
|
+
debugger
|
72
|
+
jeweler
|
73
|
+
rdoc
|
74
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 aleks tkach
|
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.markdown
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
ruby-grep
|
2
|
+
=========
|
3
|
+
|
4
|
+
ruby-grep is an enhancement over the standard unix grep utility.
|
5
|
+
|
6
|
+
- Highlights found patterns in lines
|
7
|
+
- Outputs line numbers and filenames
|
8
|
+
- Carefully indents the output
|
9
|
+
|
10
|
+
Usage
|
11
|
+
-----
|
12
|
+
ruby-grep dir_name (string | regexp)
|
13
|
+
|
14
|
+
TODO
|
15
|
+
----
|
16
|
+
1. This program is too slow cause written in ruby, rewrite back-end so that it uses original grep
|
17
|
+
2. Fix utf-8 error
|
18
|
+
|
19
|
+

|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
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 = "ruby-grep"
|
18
|
+
gem.homepage = "http://github.com/alekstkach/ruby-grep"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{enhaced grep program: higlights matches & filenames, shows line numbers}
|
21
|
+
gem.description = %Q{enhaced grep program: higlights matches & filenames, shows line numbers}
|
22
|
+
gem.email = "ale.tkachenko@gmail.com"
|
23
|
+
gem.authors = ["aleks tkach"]
|
24
|
+
gem.executables = ["ruby-grep"]
|
25
|
+
# dependencies defined in Gemfile
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rdoc/task'
|
30
|
+
Rake::RDocTask.new do |rdoc|
|
31
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
32
|
+
|
33
|
+
rdoc.rdoc_dir = 'rdoc'
|
34
|
+
rdoc.title = "ruby-grep #{version}"
|
35
|
+
rdoc.rdoc_files.include('README*')
|
36
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/ruby-grep
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require 'ruby-grep'
|
3
|
+
|
4
|
+
expression = RubyGrep::Expression.new(ARGV.drop(1).join(' '))
|
5
|
+
|
6
|
+
d = RubyGrep::Directory.new(ARGV[0])
|
7
|
+
d.files.each do |file|
|
8
|
+
puts file.colorized_filename unless file.match(expression).empty?
|
9
|
+
file.match(expression).each do |line|
|
10
|
+
puts line.colorized_line(expression)
|
11
|
+
end
|
12
|
+
end
|
data/lib/ruby-grep.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module RubyGrep
|
2
|
+
|
3
|
+
class Directory
|
4
|
+
|
5
|
+
def initialize(path)
|
6
|
+
@path = path
|
7
|
+
end
|
8
|
+
|
9
|
+
# this method finds all entries in the @path (directory) including all in all sudirectories of the
|
10
|
+
# given @path and returns them as an array of elements of type RubyGrep::File
|
11
|
+
def files
|
12
|
+
@files ||= Dir.glob(::File.join("#{@path}", "**", "{*,.*}")).select { |f| ::File.file?(f) }.
|
13
|
+
map { |file_name| RubyGrep::File.new("#{file_name}") }
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module RubyGrep
|
2
|
+
|
3
|
+
class Expression
|
4
|
+
|
5
|
+
def initialize(expression)
|
6
|
+
@expression = parse_expression(expression)
|
7
|
+
end
|
8
|
+
|
9
|
+
def value
|
10
|
+
@expression
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def parse_expression(expression)
|
16
|
+
passed_options = get_regexp_options(expression)
|
17
|
+
|
18
|
+
expression_with_no_options = expression.sub(/\/([im]+?)\Z/, '/')
|
19
|
+
|
20
|
+
if expression_with_no_options[0] == '/' && expression_with_no_options[expression_with_no_options.length - 1] == '/'
|
21
|
+
Regexp.compile(expression_with_no_options.chomp('/').sub(/\A\//, ''), passed_options )
|
22
|
+
else
|
23
|
+
expression.sub(/\A(("(.*)")|('(.*)'))\Z/, '\3\5')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# getting an array of options passed to regexp /lalala/options => [o,p,t,i,o,n,s]
|
28
|
+
def get_regexp_options(expression)
|
29
|
+
case expression.scan(/\/([im]+?)\Z/).join.split('')
|
30
|
+
when ["i"]
|
31
|
+
Regexp::IGNORECASE
|
32
|
+
when ["m"]
|
33
|
+
Regexp::MULTILINE
|
34
|
+
when ["m", "i"]
|
35
|
+
Regexp::IGNORECASE | Regexp::MULTILINE
|
36
|
+
when ["i", "m"]
|
37
|
+
Regexp::IGNORECASE | Regexp::MULTILINE
|
38
|
+
else
|
39
|
+
nil | nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding UTF-8
|
2
|
+
|
3
|
+
module RubyGrep
|
4
|
+
|
5
|
+
class File
|
6
|
+
|
7
|
+
attr_reader :file_name
|
8
|
+
|
9
|
+
def initialize(fn)
|
10
|
+
@lines = ::File.readlines(fn)
|
11
|
+
@lines.map! { |line| RubyGrep::Line.new(line, @lines.index(line), self) }
|
12
|
+
@file_name = fn
|
13
|
+
end
|
14
|
+
|
15
|
+
# this method selects lines from the file that match the expression,
|
16
|
+
# which may be a string or regexp.
|
17
|
+
def match(expression)
|
18
|
+
@lines.select { |line| line.contents.match(expression.value) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def colorized_filename
|
22
|
+
filename = @file_name.scan(/\/(\.?\w+\.\w+)|(\.\w+)/).join
|
23
|
+
colorised_filename = filename.colorize(:yellow)
|
24
|
+
@file_name.gsub(filename, colorised_filename)
|
25
|
+
end
|
26
|
+
|
27
|
+
def max_line_number_length
|
28
|
+
return @max_line_number_length if @max_line_number_length
|
29
|
+
@max_line_number_length = 1
|
30
|
+
@lines.each do |line|
|
31
|
+
if line.number.to_s.length > @max_line_number_length
|
32
|
+
@max_line_number_length = line.number.to_s.length
|
33
|
+
end
|
34
|
+
end
|
35
|
+
@max_line_number_length
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module RubyGrep
|
2
|
+
|
3
|
+
class Line
|
4
|
+
|
5
|
+
attr_reader :contents, :number, :file
|
6
|
+
|
7
|
+
def initialize(contents, number, file)
|
8
|
+
@contents = contents
|
9
|
+
@number = number + 1
|
10
|
+
@file = file
|
11
|
+
@file_name = @file.file_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def colorized_line(expression)
|
15
|
+
"\s\s\s\s#{colorize_line_number(aligned_line_number)}: #{colorize_text(expression).lstrip}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def aligned_line_number
|
19
|
+
shift = @file.max_line_number_length
|
20
|
+
sprintf("%#{shift}d", @number)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def colorize_text(expression)
|
26
|
+
matched_text = @contents.match(expression.value)[0].colorize(color: :black, background: :white)
|
27
|
+
@contents.gsub(expression.value, matched_text)
|
28
|
+
end
|
29
|
+
|
30
|
+
def colorize_line_number(number)
|
31
|
+
number.colorize(color: :magenta)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
Binary file
|
data/ruby-grep.gemspec
ADDED
@@ -0,0 +1,78 @@
|
|
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 = "ruby-grep"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["aleks tkach"]
|
12
|
+
s.date = "2013-08-12"
|
13
|
+
s.description = "enhaced grep program: higlights matches & filenames, shows line numbers"
|
14
|
+
s.email = "ale.tkachenko@gmail.com"
|
15
|
+
s.executables = ["ruby-grep"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.markdown"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.markdown",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"bin/ruby-grep",
|
30
|
+
"lib/ruby-grep.rb",
|
31
|
+
"lib/ruby-grep/directory.rb",
|
32
|
+
"lib/ruby-grep/expression.rb",
|
33
|
+
"lib/ruby-grep/file.rb",
|
34
|
+
"lib/ruby-grep/line.rb",
|
35
|
+
"ruby-grep screenshot.png",
|
36
|
+
"ruby-grep.gemspec",
|
37
|
+
"spec/directory_spec.rb",
|
38
|
+
"spec/expression_spec.rb",
|
39
|
+
"spec/file_spec.rb",
|
40
|
+
"spec/fixtures/test_file.txt",
|
41
|
+
"spec/line_spec.rb",
|
42
|
+
"spec/spec_helper.rb",
|
43
|
+
"spec/test_data.rb"
|
44
|
+
]
|
45
|
+
s.homepage = "http://github.com/alekstkach/ruby-grep"
|
46
|
+
s.licenses = ["MIT"]
|
47
|
+
s.require_paths = ["lib"]
|
48
|
+
s.rubygems_version = "2.0.3"
|
49
|
+
s.summary = "enhaced grep program: higlights matches & filenames, shows line numbers"
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
s.specification_version = 4
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_runtime_dependency(%q<colorize>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<debugger>, [">= 0"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<colorize>, [">= 0"])
|
63
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
64
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
65
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
67
|
+
s.add_dependency(%q<debugger>, [">= 0"])
|
68
|
+
end
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<colorize>, [">= 0"])
|
71
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
72
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
73
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
74
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
75
|
+
s.add_dependency(%q<debugger>, [">= 0"])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
TEMP_DIR = File.dirname(__FILE__) + '/directory_spec_test'
|
4
|
+
|
5
|
+
describe RubyGrep::Directory do
|
6
|
+
|
7
|
+
it "finds all files in the directory and sub directories" do
|
8
|
+
[ TEMP_DIR, TEMP_DIR + '/nested_level1', TEMP_DIR + '/nested_level1/nested_level2' ].each do |d|
|
9
|
+
Dir.mkdir(d)
|
10
|
+
5.times do |n|
|
11
|
+
FileUtils.touch(d + "/file#{n}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
RubyGrep::Directory.new(Dir.new(TEMP_DIR).path).files.length.should == 15
|
16
|
+
|
17
|
+
FileUtils.rm_rf(Dir.new(TEMP_DIR).path)
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns array of files of type RubyGrep::File" do
|
22
|
+
Dir.mkdir(TEMP_DIR)
|
23
|
+
Dir.mkdir(TEMP_DIR + '/nested_level1')
|
24
|
+
5.times do |n|
|
25
|
+
FileUtils.touch(TEMP_DIRECTORY_SPEC_TEST_PATH + "/file#{n}")
|
26
|
+
end
|
27
|
+
5.times do |n|
|
28
|
+
FileUtils.touch(TEMP_DIRECTORY_SPEC_TEST_PATH_INNER + "/file#{n}")
|
29
|
+
end
|
30
|
+
file_objects_array = RubyGrep::Directory.new(TEMP_DIRECTORY_SPEC_TEST_PATH).files
|
31
|
+
file_objects_array.each do |file|
|
32
|
+
file.is_a?(RubyGrep::File).should == true
|
33
|
+
end
|
34
|
+
FileUtils.rm_rf(TEMP_DIRECTORY_SPEC_TEST_PATH)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RubyGrep::Expression do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@regexp_expression = "/gimme immediate/i"
|
7
|
+
@string_expression = "gimme \"immediate\"/i"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#value" do
|
11
|
+
|
12
|
+
it "returns parsed string expression" do
|
13
|
+
RubyGrep::Expression.new(@string_expression).value.is_a?(String).should be_true
|
14
|
+
RubyGrep::Expression.new(@string_expression).value.should == "gimme 'immediate'/i"
|
15
|
+
# It doesnt replace ""/'' for some f reason
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns perced regexp expression" do
|
19
|
+
RubyGrep::Expression.new(@regexp_expression).value.is_a?(Regexp).should be_true
|
20
|
+
RubyGrep::Expression.new(@regexp_expression).value.should == /gimme immediate/i
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
data/spec/file_spec.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RubyGrep::File do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@file = RubyGrep::File.new(File.dirname(__FILE__) + '/fixtures/test_file.txt')
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#match" do
|
10
|
+
|
11
|
+
it "selects lines from the file that match the regexp" do
|
12
|
+
@file.match(RubyGrep::Expression.new("/R..y/i")).size.should == 5 # i how the fuck i am supposed to solve it
|
13
|
+
end
|
14
|
+
|
15
|
+
it "selects lines from the file that match the string" do
|
16
|
+
@file.match(RubyGrep::Expression.new("ruby")).size.should == 3
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
it "colorizes matches" do
|
22
|
+
@file.colorized_filename.should == File.dirname(__FILE__) + "/fixtures/" + "\e[0;33;49m" + "test_file.txt" + "\e[0m"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "finds the longest line number" do
|
26
|
+
@file.max_line_number_length.should == 1
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Commenting is here to help enhance the documentation.
|
2
|
+
For example, code samples, or clarification of the documentation.
|
3
|
+
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists.
|
4
|
+
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists.
|
5
|
+
You will get better, faster, help that way. ruby
|
6
|
+
You will get better, faster, help that way. ruby
|
7
|
+
You will get better, faster, help that way. ruby
|
data/spec/line_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
data/spec/test_data.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# TO ADD SMTH
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-grep
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- aleks tkach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jeweler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: debugger
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: ! 'enhaced grep program: higlights matches & filenames, shows line numbers'
|
98
|
+
email: ale.tkachenko@gmail.com
|
99
|
+
executables:
|
100
|
+
- ruby-grep
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files:
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.markdown
|
105
|
+
files:
|
106
|
+
- .document
|
107
|
+
- .rspec
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.markdown
|
112
|
+
- Rakefile
|
113
|
+
- VERSION
|
114
|
+
- bin/ruby-grep
|
115
|
+
- lib/ruby-grep.rb
|
116
|
+
- lib/ruby-grep/directory.rb
|
117
|
+
- lib/ruby-grep/expression.rb
|
118
|
+
- lib/ruby-grep/file.rb
|
119
|
+
- lib/ruby-grep/line.rb
|
120
|
+
- ruby-grep screenshot.png
|
121
|
+
- ruby-grep.gemspec
|
122
|
+
- spec/directory_spec.rb
|
123
|
+
- spec/expression_spec.rb
|
124
|
+
- spec/file_spec.rb
|
125
|
+
- spec/fixtures/test_file.txt
|
126
|
+
- spec/line_spec.rb
|
127
|
+
- spec/spec_helper.rb
|
128
|
+
- spec/test_data.rb
|
129
|
+
homepage: http://github.com/alekstkach/ruby-grep
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ! '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.0.3
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: ! 'enhaced grep program: higlights matches & filenames, shows line numbers'
|
153
|
+
test_files: []
|