filecount 0.1.1 → 0.2.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.
data/bin/filecount CHANGED
@@ -1,13 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'filecount'
3
3
 
4
- if ARGV[0] != nil then
5
- dir = ARGV[0]
6
- else
7
- dir = "."
8
- end
9
-
10
- fc = Filecount.new
11
- fc.run(dir)
12
-
13
- puts "#{fc.filecount} file(s) found"
4
+ Filecount::Runner.execute
File without changes
@@ -0,0 +1,51 @@
1
+ module Filecount
2
+ class Counter
3
+
4
+ def initialize(options)
5
+ @options = options
6
+ @count = 0
7
+ @start_dir
8
+ end
9
+
10
+ def self.execute(options)
11
+ new(options).execute
12
+ end
13
+
14
+ def execute()
15
+ if ARGV[0] != nil and File.directory?(ARGV[0])
16
+ count(ARGV[0])
17
+ elsif ARGV[0] != nil
18
+ puts "Directory '#{ARGV[0]}' not found"
19
+ exit
20
+ else
21
+ count(".")
22
+ end
23
+ @count
24
+ end
25
+
26
+ def count (directory)
27
+ Dir.foreach(directory) do |file|
28
+ if file != '.' && file != '..' then
29
+ if @options[:dotfiles] == nil && file[0].chr == "." && file != '.git'
30
+ next
31
+ end
32
+ f = "#{directory}/#{file}"
33
+
34
+ if File.directory?(f)
35
+ if @options[:count_git_dir] == nil && file == '.git'
36
+ next
37
+ end
38
+ count(f)
39
+ else
40
+ if @options[:verbose]
41
+ puts f
42
+ end
43
+ @count += 1
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+
50
+ end
51
+ end
@@ -0,0 +1,49 @@
1
+ require 'optparse'
2
+ module Filecount
3
+ class Runner
4
+ def initialize
5
+ @options = {}
6
+ parse_options
7
+ end
8
+
9
+ def self.execute
10
+ new().execute
11
+ end
12
+
13
+ def execute
14
+ count = Counter.execute(@options)
15
+ puts "-- #{count} files found"
16
+ end
17
+
18
+ def parse_options
19
+ optparse = OptionParser.new do |opts|
20
+ opts.banner = 'Usage: filecount [options] directory'
21
+
22
+ opts.on('-d', '--dotfiles', 'Follow dotfiles and directories') do
23
+ @options[:dotfiles] = true
24
+ end
25
+
26
+ opts.on('-g', '--count-git-dir', 'Count files in git directory') do
27
+ @options[:count_git_dir] = true
28
+ end
29
+
30
+ opts.on('-v', '--verbose', 'Display counted files') do
31
+ @options[:verbose] = true
32
+ end
33
+
34
+ opts.on('-h', '--help', 'Display this screen') do
35
+ puts opts
36
+ exit
37
+ end
38
+ end
39
+
40
+ begin
41
+ optparse.parse!
42
+ rescue
43
+ puts "Invalid options"
44
+ puts optparse
45
+ exit
46
+ end
47
+ end
48
+ end
49
+ end
data/lib/filecount.rb CHANGED
@@ -1,19 +1,3 @@
1
- class Filecount
2
- attr_reader :filecount
3
- def initialize
4
- @filecount = 0
5
- end
1
+ require 'filecount/runner'
2
+ require 'filecount/counter'
6
3
 
7
- def run (directory)
8
- Dir.foreach(directory) do |file|
9
- if file != '.' && file != '..' then
10
- f = "#{directory}/#{file}"
11
- if File.directory?(f)
12
- run(f)
13
- else
14
- @filecount += 1
15
- end
16
- end
17
- end
18
- end
19
- end
data/lib/run.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'filecount'
2
+
3
+ Filecount::Runner.execute
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filecount
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Markus Nilsson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-28 00:00:00 +02:00
18
+ date: 2010-07-30 00:00:00 +02:00
19
19
  default_executable: filecount
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -43,6 +43,10 @@ extra_rdoc_files:
43
43
  - README.rdoc
44
44
  files:
45
45
  - lib/filecount.rb
46
+ - lib/filecount/args.rb
47
+ - lib/filecount/counter.rb
48
+ - lib/filecount/runner.rb
49
+ - lib/run.rb
46
50
  - LICENSE
47
51
  - README.rdoc
48
52
  - test/helper.rb