ackr 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -14
- data/TODO +3 -3
- data/VERSION +1 -1
- data/bin/ackr +1 -1
- data/lib/ackr.rb +5 -3
- data/lib/ackr/finder.rb +14 -32
- data/lib/ackr/search.rb +48 -0
- metadata +2 -1
data/Rakefile
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
# todo: replace GEM by th gem name
|
4
|
-
|
5
3
|
require 'rake'
|
6
4
|
require 'rspec/core/rake_task'
|
7
5
|
|
@@ -21,15 +19,3 @@ task :reek do
|
|
21
19
|
args = files.join(' ')
|
22
20
|
sh "reek --quiet #{args} | ./reek.sed"
|
23
21
|
end
|
24
|
-
|
25
|
-
desc 'Build GEM & install it'
|
26
|
-
task :install do
|
27
|
-
sh "gem build GEM.gemspec"
|
28
|
-
f = FileList['GEM*gem'].to_a
|
29
|
-
sh "gem install #{f.first} --no-rdoc --no-ri"
|
30
|
-
end
|
31
|
-
|
32
|
-
desc 'Generate yard documentation for developpers'
|
33
|
-
task :doc do
|
34
|
-
exec 'yardoc --title "GEM Documentation" - NEWS COPYING VERSION'
|
35
|
-
end
|
data/TODO
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
Écrire le readme
|
2
|
-
|
3
|
-
use reek
|
2
|
+
travis-ci
|
4
3
|
|
5
4
|
---------------------------
|
6
5
|
|
@@ -8,7 +7,8 @@ use reek
|
|
8
7
|
[ok]case insensitive
|
9
8
|
[ok]nom du fichier en couleur
|
10
9
|
[ok]terme de la recherche en gras
|
11
|
-
|
10
|
+
[ok]ne pas chercher dans les dossiers/fichiers cachés
|
11
|
+
supprimer les espaces/tab avant/après
|
12
12
|
1|.le point signale que un (ou des) espaces ont été supprimés
|
13
13
|
une ligne sur le terminal fait 80 char max
|
14
14
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1
|
1
|
+
0.1.1
|
data/bin/ackr
CHANGED
data/lib/ackr.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
require 'ackr/
|
3
|
+
require 'ackr/search'
|
4
4
|
require 'ackr/colorizer'
|
5
|
+
require 'ackr/finder'
|
5
6
|
|
6
7
|
module Ackr
|
7
8
|
# Method taken from: https://github.com/djberg96/ptools
|
@@ -20,7 +21,8 @@ module Ackr
|
|
20
21
|
# based on Perl's -B switch).
|
21
22
|
#
|
22
23
|
def self.binary?(file)
|
23
|
-
|
24
|
-
|
24
|
+
str = (File.read(file, File.stat(file).blksize) || "").split(//)
|
25
|
+
size = str.size
|
26
|
+
((size - str.grep(" ".."~").size) / size.to_f) > 0.30
|
25
27
|
end
|
26
28
|
end
|
data/lib/ackr/finder.rb
CHANGED
@@ -1,41 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
module Ackr
|
4
|
-
class Finder
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
end
|
5
|
+
# All 'find a file' relatives.
|
6
|
+
module Finder
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
# Public: Get all files to look for.
|
9
|
+
#
|
10
|
+
# Files of interest are those who are
|
11
|
+
# + not directory
|
12
|
+
# + not binary
|
13
|
+
# + not hidden
|
14
|
+
#
|
15
|
+
# Returns an Enumerator of String filename.
|
16
|
+
def self.all_files
|
17
|
+
Dir.glob('**/*').each do |file|
|
18
|
+
next if (File.directory?(file) || Ackr::binary?(file))
|
19
|
+
yield(file)
|
16
20
|
end
|
17
21
|
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def search
|
22
|
-
results = search_into_file
|
23
|
-
unless results.empty?
|
24
|
-
puts Colorizer::for_file(@file)
|
25
|
-
results.each {|r| puts r}
|
26
|
-
puts ""
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def search_into_file
|
31
|
-
result = []
|
32
|
-
File.readlines(@file).each_with_index do |line, i|
|
33
|
-
if line.downcase.include?(@search_term)
|
34
|
-
result << "#{'%4i' % i}| #{Colorizer::for_line(line, @search_term)}"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
result
|
38
|
-
end
|
39
|
-
|
40
22
|
end
|
41
23
|
end
|
data/lib/ackr/search.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Ackr
|
4
|
+
|
5
|
+
# Search for an expression into all text files under
|
6
|
+
# current directory AND print results.
|
7
|
+
#
|
8
|
+
# FIXME Separate behaviours: search / print
|
9
|
+
class Search
|
10
|
+
|
11
|
+
# Public:
|
12
|
+
#
|
13
|
+
# search_term - The String to look for.
|
14
|
+
def initialize search_term
|
15
|
+
@search_term = search_term.downcase
|
16
|
+
end
|
17
|
+
|
18
|
+
# Public: Launch the search.
|
19
|
+
def run
|
20
|
+
Finder::all_files do |file|
|
21
|
+
@file = file
|
22
|
+
search
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def search
|
29
|
+
results = search_into_file
|
30
|
+
unless results.empty?
|
31
|
+
puts Colorizer::for_file(@file)
|
32
|
+
results.each {|res| puts res}
|
33
|
+
puts ""
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def search_into_file
|
38
|
+
result = []
|
39
|
+
File.readlines(@file).each_with_index do |line, idx|
|
40
|
+
if line.downcase.include?(@search_term)
|
41
|
+
result << "#{'%4i' % (idx + 1)}| #{Colorizer::for_line(line, @search_term)}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ackr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -36,6 +36,7 @@ extra_rdoc_files: []
|
|
36
36
|
files:
|
37
37
|
- lib/ackr.rb
|
38
38
|
- lib/ackr/finder.rb
|
39
|
+
- lib/ackr/search.rb
|
39
40
|
- lib/ackr/colorizer.rb
|
40
41
|
- bin/ackr
|
41
42
|
- VERSION
|