Class: MetricFu::HotspotRankedProblemLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sub_table, granularity) ⇒ HotspotRankedProblemLocation

Returns a new instance of HotspotRankedProblemLocation.



7
8
9
10
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 7

def initialize(sub_table, granularity)
  @sub_table = sub_table
  @granularity = granularity
end

Instance Attribute Details

#granularityObject (readonly)

Returns the value of attribute granularity.



6
7
8
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 6

def granularity
  @granularity
end

#sub_tableObject (readonly)

Returns the value of attribute sub_table.



6
7
8
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 6

def sub_table
  @sub_table
end

Instance Method Details

#assert_sub_table_has_dataObject



64
65
66
67
68
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 64

def assert_sub_table_has_data
  if (sub_table.length == 0)
    raise MetricFu::AnalysisError, "The #{item} '#{value}' does not have any rows in the analysis table"
  end
end

#class_locationObject



55
56
57
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 55

def class_location
  MetricFu::Location.get(file_path, class_name, nil)
end

#class_nameObject



39
40
41
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 39

def class_name
  first_row.class_name
end

#file_locationObject



47
48
49
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 47

def file_location
  MetricFu::Location.get(file_path, nil, nil)
end

#file_pathObject



35
36
37
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 35

def file_path
  first_row.file_path
end

#first_rowObject



59
60
61
62
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 59

def first_row
  assert_sub_table_has_data
  @first_row ||= sub_table[0]
end

#locationObject



26
27
28
29
30
31
32
33
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 26

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

#method_locationObject



51
52
53
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 51

def method_location
  MetricFu::Location.get(file_path, class_name, method_name)
end

#method_nameObject



43
44
45
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 43

def method_name
  first_row.method_name
end

#problemsObject

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



22
23
24
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 22

def problems
  @problems ||= MetricFu::HotspotProblems.new(sub_table).problems
end

#to_hashObject



12
13
14
15
16
17
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 12

def to_hash
  {
    "location" => location.to_hash,
    "details" =>  MetricFu::Utility.stringify_keys(problems),
  }
end