-
Notifications
You must be signed in to change notification settings - Fork 49
/
statistics.rb
65 lines (51 loc) · 1.31 KB
/
statistics.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# encoding: utf-8
#
require_relative 'analyzer'
module Picky
# Gathers various statistics.
#
class Statistics
def initialize
@indexes = ["\033[1mIndexes analysis\033[m:"]
end
def preamble
loc = lines_of_code File.open('app/application.rb').read
@preamble ||= <<-PREAMBLE
\033[1mApplication(s)\033[m
Definition LOC: #{"%4d" % loc}
Indexes defined: #{"%4d" % Indexes.size}
PREAMBLE
end
# Gathers information about the application.
#
def application
preamble
@application = Application.apps.map &:indented_to_s
end
# Gathers information about the indexes.
#
def analyze object
object.each_category do |category|
@indexes << <<-ANALYSIS
#{"#{category.index_name}".indented_to_s}\n
#{"#{category.name}".indented_to_s(4)}\n
#{"exact\n#{Analyzer.new.analyze(category.exact).indented_to_s}".indented_to_s(6)}\n
#{"partial\n#{Analyzer.new.analyze(category.partial).indented_to_s}".indented_to_s(6)}
ANALYSIS
end
end
# Outputs all gathered statistics.
#
def to_s
<<-STATS
Picky Configuration:
#{[@preamble, @application, @indexes.join("\n")].compact.join("\n")}
STATS
end
# Internal methods.
#
def lines_of_code text
text.scan(/^\s*[^#\s].*$/).size
end
end
end