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



72
73
74
75
76
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 72

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



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

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

#class_nameObject



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

def class_name
  first_row.class_name
end

#file_locationObject



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

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

#file_pathObject



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

def file_path
  first_row.file_path
end

#first_rowObject



67
68
69
70
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 67

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

#locationObject



34
35
36
37
38
39
40
41
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 34

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



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

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

#method_nameObject



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

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



30
31
32
# File 'lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb', line 30

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

#stringify_keys(hash) ⇒ Object



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

def stringify_keys(hash)
  result = {}
  hash.each do |key, value|
    result[key.to_s] = value
  end
  result
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" =>  stringify_keys(problems),
  }
end