Class: LOCCounter::FilesCollection
- Inherits:
-
Object
- Object
- LOCCounter::FilesCollection
- Defined in:
- lib/loc_counter/files_collection.rb
Overview
A class representing a collection of arbitrary files.
Direct Known Subclasses
Constant Summary collapse
- RUBY_FILES =
Regexp for Ruby source file paths
/((Cap|Gem|Rake)file|\.(gemspec|rake|rb)|bin\/\w+)$/
Instance Attribute Summary collapse
-
#files ⇒ Array
readonly
All parsed files in the collection.
Instance Method Summary collapse
-
#counts ⇒ ActiveSupport::OrderedHash
Summarized line counts for all files in the collection.
-
#initialize(file_paths) ⇒ FilesCollection
constructor
A new instance of FilesCollection.
Constructor Details
#initialize(file_paths) ⇒ FilesCollection
Returns a new instance of FilesCollection.
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
#files ⇒ Array (readonly)
All parsed files in the collection.
6 7 8 |
# File 'lib/loc_counter/files_collection.rb', line 6 def files @files end |
Instance Method Details
#counts ⇒ ActiveSupport::OrderedHash
Summarized line counts for all files in the collection.
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 |