Sha256: 7f0a26272bfc64319dc7c8c3e22c7da811539ce9c0e5725fac38901507cf706c

Contents?: true

Size: 1.82 KB

Versions: 6

Compression:

Stored size: 1.82 KB

Contents

module MetricFu
  class HotspotRankedProblemLocation
    MetricFu.data_structures_require { 'location' }
    attr_reader :sub_table, :granularity
    def initialize(sub_table, granularity)
      @sub_table = sub_table
      @granularity = granularity
    end

    def to_hash
      {
        'location' => location.to_hash,
        'details' =>  stringify_keys(problems),
      }
    end

    def stringify_keys(hash)
      result = {}
      hash.each do |key, value|
        result[key.to_s] = value
      end
      result
    end


    # @todo redo as item,value, options = {}
    # Note that the other option for 'details' is :detailed (this isn't
    # at all clear from this method itself
    def problems
      @problems ||= MetricFu::HotspotProblems.new(sub_table).problems
    end

    def location
      @location ||= case granularity
                    when :class  then class_location
                    when :method then method_location
                    when :file   then file_location
                    else              raise ArgumentError, "Item must be :class, :method, or :file"
                    end
    end

    def file_path
      first_row.file_path
    end
    def class_name
      first_row.class_name
    end
    def method_name
      first_row.method_name
    end
    def file_location
      MetricFu::Location.get(file_path, nil, nil)
    end
    def method_location
      MetricFu::Location.get(file_path, class_name, method_name)
    end
    def class_location
      MetricFu::Location.get(file_path, class_name, nil)
    end
    def first_row
      assert_sub_table_has_data
      @first_row ||= sub_table[0]
    end
    def assert_sub_table_has_data
      if (sub_table.length==0)
        raise MetricFu::AnalysisError, "The #{item.to_s} '#{value.to_s}' does not have any rows in the analysis table"
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
metric_fu-4.6.0 lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb
metric_fu-4.5.2 lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb
metric_fu-4.5.1 lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb
metric_fu-4.4.4 lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb
metric_fu-4.4.3 lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb
metric_fu-4.4.2 lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb