Class: RailsStats::StatsCalculator
- Inherits:
-
Object
- Object
- RailsStats::StatsCalculator
- 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
-
#code_loc ⇒ Object
readonly
Returns the value of attribute code_loc.
-
#code_total ⇒ Object
readonly
Returns the value of attribute code_total.
-
#files_total ⇒ Object
readonly
Returns the value of attribute files_total.
-
#grand_total ⇒ Object
readonly
Returns the value of attribute grand_total.
-
#pack_roots ⇒ Object
readonly
Returns the value of attribute pack_roots.
-
#polymorphic ⇒ Object
readonly
Returns the value of attribute polymorphic.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#schema_path ⇒ Object
readonly
Returns the value of attribute schema_path.
-
#statistics ⇒ Object
readonly
Returns the value of attribute statistics.
-
#statistics_by_group ⇒ Object
readonly
Returns the value of attribute statistics_by_group.
-
#structure_path ⇒ Object
readonly
Returns the value of attribute structure_path.
-
#test_loc ⇒ Object
readonly
Returns the value of attribute test_loc.
-
#tests_total ⇒ Object
readonly
Returns the value of attribute tests_total.
Instance Method Summary collapse
-
#initialize(root_directory) ⇒ StatsCalculator
constructor
A new instance of StatsCalculator.
-
#packs? ⇒ Boolean
Returns true when the application is split into packs/components, i.e.
-
#totals_for(group_statistics) ⇒ Object
Given a => CodeStatisticsCalculator hash (such as one of the values in
statistics_by_groupor the flatstatistics), returns the [code, tests, grand] totals for that group.
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_loc ⇒ Object (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_total ⇒ Object (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_total ⇒ Object (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_total ⇒ Object (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_roots ⇒ Object (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 |
#polymorphic ⇒ Object (readonly)
Returns the value of attribute polymorphic.
26 27 28 |
# File 'lib/rails_stats/stats_calculator.rb', line 26 def polymorphic @polymorphic end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
26 27 28 |
# File 'lib/rails_stats/stats_calculator.rb', line 26 def schema @schema end |
#schema_path ⇒ Object (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 |
#statistics ⇒ Object (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_group ⇒ Object (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_path ⇒ Object (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_loc ⇒ Object (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_total ⇒ Object (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.
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 |