code_statistics 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.7
1
+ 0.2.8
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{code_statistics}
8
- s.version = "0.2.7"
8
+ s.version = "0.2.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Mayer"]
12
- s.date = %q{2010-01-25}
12
+ s.date = %q{2010-02-02}
13
13
  s.default_executable = %q{code_statistics}
14
14
  s.description = %q{"This is a port of the rails 'rake stats' method so it can be made more robust and work for non rails projects. New features may eventually be added as well."}
15
15
  s.email = %q{dan@devver.net}
@@ -13,6 +13,7 @@ module CodeStatistics
13
13
  @ignore_files = collect_files_to_ignore(ignore_file_globs)
14
14
 
15
15
  directories_to_search = ['app','test','spec','merb','features', 'bin']
16
+ directories_to_search = remove_included_pairs(directories_to_search, @pairs)
16
17
  recursively_add_directories(directories_to_search)
17
18
 
18
19
  @pairs.each do |key, dir_path|
@@ -79,10 +80,16 @@ module CodeStatistics
79
80
  end
80
81
 
81
82
  private
83
+
82
84
  def calculate_statistics
83
85
  @pairs.inject({}) { |stats, pair| stats[pair.first] = calculate_directory_statistics(pair.last); stats }
84
86
  end
85
87
 
88
+ def remove_included_pairs(directories_to_search, pairs)
89
+ #if the user explicitly said to index the directory index it at the level specified not recursively
90
+ directories_to_search.reject{|dir| @pairs.map{|pair| pair.first}.include?(dir)}
91
+ end
92
+
86
93
  def local_file_exists?(dir,filename)
87
94
  File.exist?(File.join(dir,filename))
88
95
  end
@@ -132,17 +139,19 @@ module CodeStatistics
132
139
  end
133
140
 
134
141
  def calculate_code
135
- code_loc = 0
136
- @statistics.each { |k, v| code_loc += v['codelines'] unless test_types.include? k }
137
- code_loc
142
+ calculate_type(false)
138
143
  end
139
144
 
140
145
  def calculate_tests
141
- test_loc = 0
142
- @statistics.each { |k, v| test_loc += v['codelines'] if test_types.include? k }
143
- test_loc
146
+ calculate_type(true)
144
147
  end
145
148
 
149
+ def calculate_type(test_match)
150
+ type_loc = 0
151
+ @statistics.each { |k, v| type_loc += v['codelines'] if test_types.include?(k)==test_match }
152
+ type_loc
153
+ end
154
+
146
155
  def print_header
147
156
  print_splitter
148
157
  @print_buffer << "| Name".ljust(22)+" "+
@@ -159,10 +168,14 @@ module CodeStatistics
159
168
  def print_splitter
160
169
  @print_buffer << "+----------------------+-------+-------+---------+---------+-----+-------+\n"
161
170
  end
171
+
172
+ def x_over_y(top, bottom)
173
+ result = (top / bottom) rescue result = 0
174
+ end
162
175
 
163
176
  def print_line(name, statistics)
164
- m_over_c = (statistics["methods"] / statistics["classes"]) rescue m_over_c = 0
165
- loc_over_m = (statistics["codelines"] / statistics["methods"]) rescue loc_over_m = 0
177
+ m_over_c = x_over_y(statistics["methods"], statistics["classes"])
178
+ loc_over_m = x_over_y(statistics["codelines"], statistics["methods"])
166
179
  loc_over_m = loc_over_m - 2 if loc_over_m >= 2
167
180
 
168
181
  start = if test_types.include? name
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_statistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Mayer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-25 00:00:00 -05:00
12
+ date: 2010-02-02 00:00:00 -05:00
13
13
  default_executable: code_statistics
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency