Class: CodeStats
- Inherits:
-
Object
- Object
- CodeStats
- Defined in:
- lib/code_stats.rb,
lib/code_stats/tasks.rb,
lib/code_stats/printer.rb
Defined Under Namespace
Classes: Printer, Report, Stats, Tasks
Instance Attribute Summary collapse
-
#directories ⇒ Object
readonly
Returns the value of attribute directories.
-
#file_extensions ⇒ Object
readonly
Returns the value of attribute file_extensions.
-
#reporting_depth ⇒ Object
readonly
Returns the value of attribute reporting_depth.
Instance Method Summary collapse
-
#initialize(options) ⇒ CodeStats
constructor
A new instance of CodeStats.
- #run ⇒ Object
Constructor Details
#initialize(options) ⇒ CodeStats
Returns a new instance of CodeStats.
57 58 59 60 61 |
# File 'lib/code_stats.rb', line 57 def initialize() @directories = [:directories] ? Array([:directories]) : raise('need to specify directory') @reporting_depth = [:reporting_depth] || 0 @file_extensions = Array([:file_extensions] || 'rb') end |
Instance Attribute Details
#directories ⇒ Object (readonly)
Returns the value of attribute directories.
55 56 57 |
# File 'lib/code_stats.rb', line 55 def directories @directories end |
#file_extensions ⇒ Object (readonly)
Returns the value of attribute file_extensions.
55 56 57 |
# File 'lib/code_stats.rb', line 55 def file_extensions @file_extensions end |
#reporting_depth ⇒ Object (readonly)
Returns the value of attribute reporting_depth.
55 56 57 |
# File 'lib/code_stats.rb', line 55 def reporting_depth @reporting_depth end |
Instance Method Details
#run ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/code_stats.rb', line 63 def run reports = Hash.new{|h,k| h[k] = []} directories.each do |dir| Dir.glob(File.join(dir, '**', "*.{#{file_extensions * ','}}")) do |entry| relative_entry = entry[entry.index(dir) + dir.size, entry.size] relative_entry_parts = File.dirname(relative_entry).split(File::SEPARATOR).select{|f| not f.nil? || f.empty?} stats = Stats.new(entry) (0..reporting_depth).each do |depth| if relative_entry_parts.size >= depth reports[dir][depth] ||= {} reports[dir][depth][relative_entry_parts[0, depth]] ||= Report.new(relative_entry_parts[0, depth]) reports[dir][depth][relative_entry_parts[0, depth]] << stats end end end end reports end |