Class: RailsStats::StatsCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_stats/stats_calculator.rb

Constant Summary collapse

RAILS_APP_FOLDERS =
['models',
'controllers',
'helpers',
'mailers',
'views',
'assets']
CORE_GROUP =
"Core".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_directory) ⇒ StatsCalculator

Returns a new instance of StatsCalculator.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rails_stats/stats_calculator.rb', line 10

def initialize(root_directory)
  @root_directory = File.absolute_path(root_directory)
  @schema_path    = File.join(@root_directory, "db", "schema.rb")
  @structure_path = File.join(@root_directory, "db", "structure.sql")
  @pack_roots     = PackFinder.find(@root_directory)
  @key_concepts   = calculate_key_concepts
  @projects       = calculate_projects
  @statistics     = calculate_statistics
  @statistics_by_group = calculate_statistics_by_group
  @code_loc       = calculate_code
  @test_loc       = calculate_tests
  @schema         = calculate_create_table_calls
  @polymorphic    = calculate_polymorphic
  @files_total, @code_total, @tests_total, @grand_total = calculate_totals
end

Instance Attribute Details

#code_locObject (readonly)

Returns the value of attribute code_loc.



26
27
28
# File 'lib/rails_stats/stats_calculator.rb', line 26

def code_loc
  @code_loc
end

#code_totalObject (readonly)

Returns the value of attribute code_total.



26
27
28
# File 'lib/rails_stats/stats_calculator.rb', line 26

def code_total
  @code_total
end

#files_totalObject (readonly)

Returns the value of attribute files_total.



26
27
28
# File 'lib/rails_stats/stats_calculator.rb', line 26

def files_total
  @files_total
end

#grand_totalObject (readonly)

Returns the value of attribute grand_total.



26
27
28
# File 'lib/rails_stats/stats_calculator.rb', line 26

def grand_total
  @grand_total
end

#pack_rootsObject (readonly)

Returns the value of attribute pack_roots.



26
27
28
# File 'lib/rails_stats/stats_calculator.rb', line 26

def pack_roots
  @pack_roots
end

#polymorphicObject (readonly)

Returns the value of attribute polymorphic.



26
27
28
# File 'lib/rails_stats/stats_calculator.rb', line 26

def polymorphic
  @polymorphic
end

#schemaObject (readonly)

Returns the value of attribute schema.



26
27
28
# File 'lib/rails_stats/stats_calculator.rb', line 26

def schema
  @schema
end

#schema_pathObject (readonly)

Returns the value of attribute schema_path.



26
27
28
# File 'lib/rails_stats/stats_calculator.rb', line 26

def schema_path
  @schema_path
end

#statisticsObject (readonly)

Returns the value of attribute statistics.



26
27
28
# File 'lib/rails_stats/stats_calculator.rb', line 26

def statistics
  @statistics
end

#statistics_by_groupObject (readonly)

Returns the value of attribute statistics_by_group.



26
27
28
# File 'lib/rails_stats/stats_calculator.rb', line 26

def statistics_by_group
  @statistics_by_group
end

#structure_pathObject (readonly)

Returns the value of attribute structure_path.



26
27
28
# File 'lib/rails_stats/stats_calculator.rb', line 26

def structure_path
  @structure_path
end

#test_locObject (readonly)

Returns the value of attribute test_loc.



26
27
28
# File 'lib/rails_stats/stats_calculator.rb', line 26

def test_loc
  @test_loc
end

#tests_totalObject (readonly)

Returns the value of attribute tests_total.



26
27
28
# File 'lib/rails_stats/stats_calculator.rb', line 26

def tests_total
  @tests_total
end

Instance Method Details

#packs?Boolean

Returns true when the application is split into packs/components, i.e. there is at least one group beyond the core application.

Returns:

  • (Boolean)


32
33
34
# File 'lib/rails_stats/stats_calculator.rb', line 32

def packs?
  @pack_roots.any?
end

#totals_for(group_statistics) ⇒ Object

Given a => CodeStatisticsCalculator hash (such as one of the values in statistics_by_group or the flat statistics), returns the [code, tests, grand] totals for that group.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rails_stats/stats_calculator.rb', line 39

def totals_for(group_statistics)
  code  = CodeStatisticsCalculator.new
  tests = CodeStatisticsCalculator.new
  grand = CodeStatisticsCalculator.new

  group_statistics.each_value do |stats|
    grand.add(stats)
    stats.test ? tests.add(stats) : code.add(stats)
  end

  [code, tests, grand]
end