Class: Picky::Statistics

Inherits:
Object show all
Defined in:
lib/picky/statistics.rb

Overview

Gathers various statistics.

Instance Method Summary collapse

Constructor Details

#initializeStatistics

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 << "  \#{\"\#{category.index_name}\".indented_to_s}\\n\n  \#{\"\#{category.name}\".indented_to_s(4)}\\n\n  \#{\"exact\\n\#{Analyzer.new.analyze(category.exact).indented_to_s}\".indented_to_s(6)}\\n\n  \#{\"partial\\n\#{Analyzer.new.analyze(category.partial).indented_to_s}\".indented_to_s(6)}\n  ANALYSIS\n  end\nend\n"

#applicationObject

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

#preambleObject



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 ||= "  \\033[1mApplication(s)\\033[m\nDefinition LOC:  \#{\"%4d\" % loc}\nIndexes defined: \#{\"%4d\" % Indexes.size}\n  PREAMBLE\nend\n"

#to_sObject

Outputs all gathered statistics.



47
48
49
50
51
52
53
54
# File 'lib/picky/statistics.rb', line 47

def to_s
  "\n  Picky Configuration:\n\n  \#{[@preamble, @application, @indexes.join(\"\\n\")].compact.join(\"\\n\")}\n  STATS\nend\n"