Class: Codefuckery::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/codefuckery/counter.rb

Class Method Summary collapse

Class Method Details

.count(directory, filetypes, words, recursive) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/codefuckery/counter.rb', line 3

def self.count(directory, filetypes, words, recursive)
    if !File.exists?(directory)
        puts "ERROR: '#{directory}' does not exist"
        return nil
    end

    if !File.directory?(directory)
        puts "ERROR: '#{directory}' is not a directory"
        return nil
    end

    paths = create_paths(directory, filetypes, recursive)

    if words == nil || words.empty?
        words = Codefuckery::DEFAULT_WORDS
    end

    word_counts = {}
    words.each { |w| word_counts[w] = 0 }
    paths.each { |p| count_in_file(p, words, word_counts) }

    word_counts
end