wcr 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ddd31588bcd3e72963fd5fadb3a4a67936f6d06
4
- data.tar.gz: c2d154f33a0519ccda63eaa74db4038e5b4cc561
3
+ metadata.gz: e93bdfebe8a4efee71ea30a5bd18fe51905232dd
4
+ data.tar.gz: b61c9f61a4201552f5a39ed550c7a9780f3a1c5e
5
5
  SHA512:
6
- metadata.gz: 1bb6cbe70bc156d06bada4c32e189bcc4d8310e43feacdb3d7cb6b800cb32469ee943fd8b824b74d39909e859760b290608109b76e6fb3d9ffd9c8a7880905b7
7
- data.tar.gz: 40990e07c59cb7f7a523926f17e21a0d6b9d3fb31078d5acf02f5720fed7e3f6456ce231119fb9bae7bfda7f43cd5ff592a7c779455c0ba153527966acb00054
6
+ metadata.gz: 59a944dfa02f448d85133737bbeb31c324851bbf54aa8a0da2f2498a8ab06572068d107acc158179bc71d458c8524e915c1eef4d7bb84194731b1ebcbb582296
7
+ data.tar.gz: 9d86ddf880da421945e00e4db1aedcfa4b54fce4a31b7b713a4662367bcfb54637f5e150be0650702508ad433523eb34700b7ce0f2de32dd331f4489bde9ea54
data/README.md CHANGED
@@ -1,4 +1,71 @@
1
- wcr
2
- ===
1
+ ###WordCount-Recursive###
2
+
3
+ A wrapper on `wc` shell command. This command permit to execute `wc` recursively with a more flexible argument parser.
4
+
5
+ ####Installation####
6
+
7
+ `gem install wcr`
8
+
9
+ ####Usage####
10
+
11
+ Example of Project Architecture:
12
+
13
+ ```text
14
+ wcr/
15
+ |--bin/
16
+ |--wcr
17
+ |--lib/
18
+ |--wcr/
19
+ |--arguments_parser.rb
20
+ |--command.rb
21
+ |--wrc.rb
22
+ ...
23
+ |--wcr.gemspec
24
+ ```
25
+
26
+ #####execute `wcr` on `lib` folder:#####
27
+
28
+ Output:
29
+
30
+ ```shell
31
+ $> wcr ./lib
32
+ 38 88 818 ./lib/wcr/arguments_parser.rb
33
+ 13 33 343 ./lib/wcr/command.rb
34
+ 0 2 21 ./lib/wcr.rb
35
+ 51 123 1182 total
36
+ $>
37
+ ```
38
+
39
+ The options parser is particulary flexible:
40
+
41
+ ```shell
42
+ $> wcr -l ./lib -w ./bin
43
+ 38 88 ./lib/wcr/arguments_parser.rb
44
+ 13 33 ./lib/wcr/command.rb
45
+ 0 2 ./lib/wcr.rb
46
+ 7 13 ./bin/wcr
47
+ 58 136 total
48
+ $>
49
+ ```
50
+
51
+ ####Options####
52
+
53
+ Use `-h` options to display hidden files.
54
+
55
+ ####About This Gem####
56
+
57
+ - This program is written using the ruby stdlib without any dependencies.
58
+ - It's a wrapper of `wc` shell command. So, feel free to check `man wc` for more information.
59
+
60
+ ####Issues####
61
+
62
+ Before reporting a problem check the issue list.
63
+
64
+ ####About Me####
65
+
66
+ More information [here](https://www.linkedin.com/pub/mehdi-farsi/48/ba9/336).
67
+
68
+ Feel free to follow me on [Twitter](https://twitter.com/farsi_mehdi).
69
+
70
+ thanks ! :)
3
71
 
4
- A wrapper on `wc` command. Permit to execute `wc` recursively with a more flexible argument parser.
@@ -3,15 +3,19 @@ require 'optparse'
3
3
  module WordCountRecursive
4
4
  class ArgumentsParser
5
5
  def parse
6
- options = {command_opts: ""}
6
+ options = {command_opts: "", hidden_files: "| grep -v '/\\.'"}
7
7
 
8
8
  o = ::OptionParser.new do |opts|
9
- opts.banner = "usage: wc [-clmw] [file ...]"
9
+ opts.banner = "usage: wc [-clhmw] [file ...]"
10
10
 
11
11
  opts.on("-c") do |c|
12
12
  options[:command_opts] += " -c"
13
13
  end
14
14
 
15
+ opts.on("-h") do |h|
16
+ options[:hidden_files] = ""
17
+ end
18
+
15
19
  opts.on("-l") do |l|
16
20
  options[:command_opts] += " -l"
17
21
  end
@@ -31,6 +35,7 @@ module WordCountRecursive
31
35
  $stderr.puts o.banner
32
36
  exit
33
37
  end
38
+ # TODO: ugly code to refactor :(
34
39
  [(ARGV.length > 0 ? ARGV.join(' ') : nil), options]
35
40
  end
36
41
  end
data/lib/wcr/command.rb CHANGED
@@ -4,11 +4,12 @@ module WordCountRecursive
4
4
  class Command
5
5
  def initialize
6
6
  @paths, @options = ::WordCountRecursive::ArgumentsParser.new.parse
7
- @command = `wc #{@options[:command_opts]} #{"\`find #{@paths || '.'} -type f\`"}`
7
+ @command = `wc #{@options[:command_opts]} #{"\`find #{@paths || '.'} -type f #{@options[:hidden_files]}\`"}`
8
+ @command = @command.split('\n').grep(/^[^\.]/)
8
9
  end
9
10
 
10
11
  def wcr
11
- @command.each_line {|line| puts line.chomp }
12
+ @command.each {|line| puts line.chomp }
12
13
  end
13
14
  end
14
15
  end
data/wcr.gemspec CHANGED
@@ -1,18 +1,16 @@
1
- # encoding: utf-8
2
- $:.push File.expand_path("../lib", __FILE__)
3
-
4
1
  Gem::Specification.new do |s|
5
2
  s.name = 'wcr'
6
- s.version = '0.0.2'
3
+ s.version = '0.1.0'
7
4
  s.date = '2014-11-18'
8
5
  s.summary = "wc-recursive"
9
6
  s.description = "A wrapper on wc command. Permit to execute wc recursively with a more flexible argument parser."
7
+ s.homepage = 'https://github.com/mehdi-farsi/wcr'
10
8
  s.authors = ["Mehdi Farsi"]
11
9
  s.email = 'mehdifarsi.pro@gmail.com'
12
10
  s.files = `git ls-files`.split("\n")
13
11
  s.require_paths = ["lib"]
14
- s.homepage = 'http://rubygems.org/gems/wcr'
15
12
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
13
  s.required_ruby_version = '>= 1.9.3'
17
14
  s.license = 'MIT'
15
+ s.post_install_message = "Thanks for installing! You can follow me on Twitter: @farsi_mehdi"
18
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wcr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehdi Farsi
@@ -26,11 +26,11 @@ files:
26
26
  - lib/wcr/arguments_parser.rb
27
27
  - lib/wcr/command.rb
28
28
  - wcr.gemspec
29
- homepage: http://rubygems.org/gems/wcr
29
+ homepage: https://github.com/mehdi-farsi/wcr
30
30
  licenses:
31
31
  - MIT
32
32
  metadata: {}
33
- post_install_message:
33
+ post_install_message: 'Thanks for installing! You can follow me on Twitter: @farsi_mehdi'
34
34
  rdoc_options: []
35
35
  require_paths:
36
36
  - lib