Sha256: 821fedabea30b09cbed443478ec58d829e2a2e13b3b56b572814489df9d3c3f4

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

module Kolekti
  module Radon
    module Parser
      class Base < Kolekti::Parser
        attr_reader :metric_configurations, :persistence_strategy, :logger

        def initialize(metric_configurations, persistence_strategy, logger)
          @metric_configurations = metric_configurations
          @persistence_strategy = persistence_strategy
          @logger = logger
        end

        def command; raise NotImplementedError; end

        # Default implementation is somewhat naive, but works for both Raw and
        # Maintainability Index - it just expects keys named the same as the
        # code for each metric configuration.
        def parse(raw_output)
          raw_output.each do |file_name, result_hash|
            module_name = self.class.parse_file_name(file_name)

            @metric_configurations.each do |metric_configuration|
              value = result_hash[metric_configuration.metric.code] unless result_hash.key?('error')
              value ||= self.class.default_value

              @persistence_strategy.create_tree_metric_result(
                metric_configuration, module_name, value.to_f,
                KalibroClient::Entities::Miscellaneous::Granularity::PACKAGE)
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kolekti_radon-5.0.0 lib/kolekti/radon/parser/base.rb