lib/faml/stats.rb in faml-0.3.3 vs lib/faml/stats.rb in faml-0.3.4

- old
+ new

@@ -6,14 +6,16 @@ module Faml class Stats Info = Struct.new( :empty_attribute_count, :static_attribute_count, + :static_id_or_class_attribute_count, :dynamic_attribute_count, :dynamic_attribute_with_data_count, :dynamic_attribute_with_newline_count, :ruby_attribute_count, + :multi_attribute_count, :ast_types ) do def initialize(*) super self.ast_types ||= Hash.new { |h, k| h[k] = 0 } @@ -99,42 +101,50 @@ def collect_attribute_info(info, ast) if ast.attributes.empty? if ast.static_class.empty? && ast.static_id.empty? info.empty_attribute_count += 1 else - info.static_attribute_count += 1 + info.static_id_or_class_attribute_count += 1 end else static_hash_parser = StaticHashParser.new if static_hash_parser.parse("{#{ast.attributes}}") if static_hash_parser.dynamic_attributes.empty? info.static_attribute_count += 1 else - if static_hash_parser.dynamic_attributes.key?('data') + if static_hash_parser.dynamic_attributes.key?('data') || static_hash_parser.dynamic_attributes.key?(:data) info.dynamic_attribute_with_data_count += 1 elsif ast.attributes.include?("\n") info.dynamic_attribute_with_newline_count += 1 else info.dynamic_attribute_count += 1 end end else - info.ruby_attribute_count += 1 + call_ast = Parser::CurrentRuby.parse("call(#{ast.attributes})") + if call_ast.type == :send && call_ast.children[0].nil? && call_ast.children[1] == :call && !call_ast.children[3].nil? + info.multi_attribute_count += 1 + else + info.ruby_attribute_count += 1 + end end end end def report_attribute_stats(info) static = info.static_attribute_count dynamic = info.dynamic_attribute_count + info.dynamic_attribute_with_data_count + info.dynamic_attribute_with_newline_count - ruby = info.ruby_attribute_count + ruby = info.ruby_attribute_count + info.multi_attribute_count total = static + dynamic + ruby puts 'Attribute stats' + printf(" Empty attributes: %d\n", info.empty_attribute_count) + printf(" Attributes with id or class only: %d\n", info.static_id_or_class_attribute_count) printf(" Static attributes: %d (%.2f%%)\n", static, static * 100.0 / total) printf(" Dynamic attributes: %d (%.2f%%)\n", dynamic, dynamic * 100.0 / total) printf(" with data: %d\n", info.dynamic_attribute_with_data_count) printf(" with newline: %d\n", info.dynamic_attribute_with_newline_count) printf(" Ruby attributes: %d (%.2f%%)\n", ruby, ruby * 100.0 / total) + printf(" with multiple arguments: %d\n", info.multi_attribute_count) end def report_ast_stats(info) total = info.ast_types.values.inject(0, :+) puts 'AST stats'