Class: CodeStatistics::CodeStatistics
- Inherits:
-
Object
- Object
- CodeStatistics::CodeStatistics
- Defined in:
- lib/code_statistics/code_statistics.rb
Overview
:nodoc:
Constant Summary collapse
- FILTER =
/.*\.(rb|feature)$/
Instance Attribute Summary collapse
-
#print_buffer ⇒ Object
readonly
Returns the value of attribute print_buffer.
Instance Method Summary collapse
- #add_sub_directory(entries, dir) ⇒ Object
- #collect_files_to_ignore(ignore_file_globs) ⇒ Object
-
#initialize(pairs, ignore_file_globs = []) ⇒ CodeStatistics
constructor
A new instance of CodeStatistics.
- #recursively_add_directories(dirs) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(pairs, ignore_file_globs = []) ⇒ CodeStatistics
Returns a new instance of CodeStatistics.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/code_statistics/code_statistics.rb', line 10 def initialize(pairs, ignore_file_globs = []) @pairs = pairs @test_types = [] @print_buffer = "" directory = Dir.pwd @ignore_files = collect_files_to_ignore(ignore_file_globs) @pairs = remove_duplicate_pairs(@pairs) directories_to_search = ['app','test','spec','merb', 'bin'] directories_to_search = remove_included_pairs(directories_to_search, @pairs) recursively_add_directories(directories_to_search) add_test_types(@pairs) @statistics = calculate_statistics @total = calculate_total if pairs.length > 1 end |
Instance Attribute Details
#print_buffer ⇒ Object (readonly)
Returns the value of attribute print_buffer.
8 9 10 |
# File 'lib/code_statistics/code_statistics.rb', line 8 def print_buffer @print_buffer end |
Instance Method Details
#add_sub_directory(entries, dir) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/code_statistics/code_statistics.rb', line 39 def add_sub_directory(entries, dir) has_directories = false entries = entries.reject{ |entry| entry=='.' || entry=='..' } entries.each do |entry| entry_path = File.join(dir,entry) if File.directory?(entry_path) if Dir.entries(entry_path).select{|path| path.match(FILTER)}.length > 0 @pairs << [entry_path, entry_path] has_directories = true else sub_has_directories = add_sub_directory(Dir.entries(entry_path), entry_path) has_directories = true if sub_has_directories if sub_has_directories == false && Dir.entries(entry_path).select{|path| path.match(FILTER)}.length > 0 @pairs << [entry_path, entry_path] has_directories = true end end end end has_directories end |
#collect_files_to_ignore(ignore_file_globs) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/code_statistics/code_statistics.rb', line 61 def collect_files_to_ignore(ignore_file_globs) files_to_remove = [] ignore_file_globs.each do |glob| files_to_remove.concat(Dir[glob]) end files_to_remove.map{ |filepath| File.(filepath)} end |
#recursively_add_directories(dirs) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/code_statistics/code_statistics.rb', line 28 def recursively_add_directories(dirs) dirs.each do |dir| if File.directory?(dir) entries = Dir.entries(dir) entries = entries.reject{ |entry| entry=='.' || entry=='..' } has_directories = add_sub_directory(entries, dir) @pairs << [dir, dir] unless has_directories end end end |
#to_s ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/code_statistics/code_statistics.rb', line 69 def to_s @print_buffer = '' print_header @pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) } print_splitter if @total print_line("Total", @total) print_splitter end print_code_test_stats @print_buffer end |