Class: LOCCounter::FilesCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/loc_counter/files_collection.rb

Overview

A class representing a collection of arbitrary files.

Direct Known Subclasses

Project

Constant Summary collapse

RUBY_FILES =

Regexp for Ruby source file paths

/((Cap|Gem|Rake)file|\.(gemspec|rake|rb)|bin\/\w+)$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_paths) ⇒ FilesCollection

Returns a new instance of FilesCollection.

Parameters:

  • file_paths (Array)

    Paths to files being processed



12
13
14
15
16
17
# File 'lib/loc_counter/files_collection.rb', line 12

def initialize(file_paths)
  @files = []
  file_paths.each do |path|
    @files << SourceFile.new(path) if path =~ RUBY_FILES
  end
end

Instance Attribute Details

#filesArray (readonly)

All parsed files in the collection.

Returns:

  • (Array)


6
7
8
# File 'lib/loc_counter/files_collection.rb', line 6

def files
  @files
end

Instance Method Details

#countsActiveSupport::OrderedHash

Summarized line counts for all files in the collection.

Examples:

project = LOCCounter::Project.new(path)
project.counts
# => {
#    :total => 1606,
#    :empty => 292,
# :comments => 360,
#     :code => 954,
#    :files => 43
# }

Returns:

  • (ActiveSupport::OrderedHash)

See Also:



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/loc_counter/files_collection.rb', line 32

def counts
  total_counts = ActiveSupport::OrderedHash.new
  [:total, :empty, :comments, :code].each { |type| total_counts[type] = 0 }
  
  @files.each do |file|
    total_counts.keys.each do |type|
      total_counts[type] += file.counts[type]
    end
  end
  
  total_counts.merge(:files => @files.count)
end