Class: Picky::Statistics
Overview
Gathers various statistics.
Instance Method Summary collapse
-
#analyze(object) ⇒ Object
Gathers information about the indexes.
-
#application ⇒ Object
Gathers information about the application.
-
#initialize ⇒ Statistics
constructor
A new instance of Statistics.
-
#lines_of_code(text) ⇒ Object
Internal methods.
- #preamble ⇒ Object
-
#to_s ⇒ Object
Outputs all gathered statistics.
Constructor Details
#initialize ⇒ Statistics
Returns a new instance of Statistics.
11 12 13 |
# File 'lib/picky/statistics.rb', line 11 def initialize @indexes = ["\033[1mIndexes analysis\033[m:"] end |
Instance Method Details
#analyze(object) ⇒ Object
Gathers information about the indexes.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/picky/statistics.rb', line 34 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 |
#application ⇒ Object
Gathers information about the application.
27 28 29 30 |
# File 'lib/picky/statistics.rb', line 27 def application preamble @application = Application.apps.map &:indented_to_s end |
#lines_of_code(text) ⇒ Object
Internal methods.
59 60 61 |
# File 'lib/picky/statistics.rb', line 59 def lines_of_code text text.scan(/^\s*[^#\s].*$/).size end |
#preamble ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/picky/statistics.rb', line 15 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 |
#to_s ⇒ Object
Outputs all gathered statistics.
47 48 49 50 51 52 53 54 |
# File 'lib/picky/statistics.rb', line 47 def to_s <<-STATS Picky Configuration: #{[@preamble, @application, @indexes.join("\n")].compact.join("\n")} STATS end |