Class: Filecount::Counter
- Inherits:
-
Object
- Object
- Filecount::Counter
- Defined in:
- lib/filecount/counter.rb
Instance Attribute Summary collapse
-
#file_count ⇒ Object
Returns the value of attribute file_count.
-
#start_dir ⇒ Object
Returns the value of attribute start_dir.
Class Method Summary collapse
Instance Method Summary collapse
- #count(directory) ⇒ Object
- #execute ⇒ Object
-
#initialize(options) ⇒ Counter
constructor
A new instance of Counter.
Constructor Details
#initialize(options) ⇒ Counter
Returns a new instance of Counter.
5 6 7 8 9 |
# File 'lib/filecount/counter.rb', line 5 def initialize() @options = @file_count = 0 @start_dir end |
Instance Attribute Details
#file_count ⇒ Object
Returns the value of attribute file_count.
4 5 6 |
# File 'lib/filecount/counter.rb', line 4 def file_count @file_count end |
#start_dir ⇒ Object
Returns the value of attribute start_dir.
4 5 6 |
# File 'lib/filecount/counter.rb', line 4 def start_dir @start_dir end |
Class Method Details
.execute(options) ⇒ Object
11 12 13 |
# File 'lib/filecount/counter.rb', line 11 def self.execute() new().execute end |
Instance Method Details
#count(directory) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/filecount/counter.rb', line 29 def count (directory) Dir.foreach(directory) do |file| if file != '.' && file != '..' then if @options[:dotfiles] == nil && file[0].chr == "." && file != '.git' next end f = "#{directory}/#{file}" if File.directory?(f) if @options[:count_git_dir] == nil && file == '.git' next end count(f) else if @options[:verbose] puts f end @file_count += 1 end end end end |
#execute ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/filecount/counter.rb', line 15 def execute() if ARGV[0] != nil and File.directory?(ARGV[0]) @start_dir = File.(ARGV[0]) count(ARGV[0]) elsif ARGV[0] != nil puts "Directory '#{ARGV[0]}' not found" exit else @start_dir = File.(".") count(".") end @file_count end |