Module: Reviser::Criteria::CodeAnalysis
- Includes:
- Helpers::Project
- Defined in:
- lib/reviser/criteria/code_analysis.rb
Overview
Basic criteria
Instance Method Summary collapse
-
#all_files ⇒ Object
Project's directory contents.
-
#comments_count ⇒ Object
The number of lines of comments.
-
#find_comments(comm) ⇒ Object
Translates a sub-match returned by scan into raw comments string.
-
#lines_count ⇒ Object
The total amount of lines of code.
-
#src_files ⇒ Object
All files matching the extenstion language list (note that Cfg[:extension] must be an array).
Methods included from Helpers::Project
#files, #manufacture, #missing_files, #prepare, #sources
Instance Method Details
#all_files ⇒ Object
Returns project's directory contents.
36 37 38 |
# File 'lib/reviser/criteria/code_analysis.rb', line 36 def all_files files.join("\r") end |
#comments_count ⇒ Object
Returns the number of lines of comments.
62 63 64 65 66 67 |
# File 'lib/reviser/criteria/code_analysis.rb', line 62 def comments_count tab_comments = sources.inject([]) { |t, f| t << IO.read(f).scrub.scan(Cfg[:regex_comments]) } lines = tab_comments.inject('') { |s, comm| s << find_comments(comm) }.split "\n" lines.size end |
#find_comments(comm) ⇒ Object
Translates a sub-match returned by scan into raw comments string
73 74 75 |
# File 'lib/reviser/criteria/code_analysis.rb', line 73 def find_comments(comm) comm.inject('') { |t, l| t << l.detect { |a| (a != nil) && !a.strip.empty? } + "\n" } end |
#lines_count ⇒ Object
Returns the total amount of lines of code.
51 52 53 54 55 56 57 |
# File 'lib/reviser/criteria/code_analysis.rb', line 51 def lines_count count = sources.inject(0) { |sum, f| sum + File.open(f).readlines.select { |l| !l.chomp.empty? }.size } count - comments_count # FIXME end |
#src_files ⇒ Object
Returns all files matching the extenstion language list (note that Cfg[:extension] must be an array).
44 45 46 |
# File 'lib/reviser/criteria/code_analysis.rb', line 44 def src_files sources.join("\r") end |