Class: CukeSniffer::SummaryHelper

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/cuke_sniffer/summary_helper.rb

Overview

Author

Robert Cochran ([email protected])

Copyright

Copyright © 2014 Robert Cochran

License

Distributes under the MIT License

Mixins: CukeSniffer::Constants A static class used to help with handling summary data for CukeSniffer::CLI

Constant Summary

Constants included from Constants

Constants::COMMENT_REGEX, Constants::DATE_REGEX, Constants::DEFAULT_OUTPUT_FILE_NAME, Constants::FILE_IGNORE_LIST, Constants::HOOK_REGEX, Constants::HOOK_STYLES, Constants::MARKUP_SOURCE, Constants::SCENARIO_TITLE_STYLES, Constants::STEP_DEFINITION_REGEX, Constants::STEP_REGEX, Constants::STEP_STYLES, Constants::TAG_REGEX, Constants::THRESHOLDS

Class Method Summary collapse

Class Method Details

.assess_rule_target_list(rule_target_list, type) ⇒ Object

Returns a summary hash for the rule_target_list



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cuke_sniffer/summary_helper.rb', line 55

def self.assess_rule_target_list(rule_target_list, type)
  assessment_hash = initialize_assessment_hash(rule_target_list, type)
  rule_target_list.each do |rule_target|
    score = rule_target.score
    assessment_hash[:total_score] += score
    assessment_hash[rule_target.good? ? :good : :bad] += 1
    if score < assessment_hash[:min]
      assessment_hash[:min] = score
      assessment_hash[:min_file] = rule_target.location
    end
    if score > assessment_hash[:max]
      assessment_hash[:max] = score
      assessment_hash[:max_file] = rule_target.location
    end
    rule_target.rules_hash.each_key do |key|
      assessment_hash[:improvement_list][key] ||= 0
      assessment_hash[:improvement_list][key] += rule_target.rules_hash[key]
    end
  end
  assessment_hash[:average] = (assessment_hash[:total_score].to_f/rule_target_list.count.to_f).round(2)
  assessment_hash
end

.initialize_assessment_hash(rule_target_list, type) ⇒ Object

Initializes an assessment hash for the rule target list



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cuke_sniffer/summary_helper.rb', line 38

def self.initialize_assessment_hash(rule_target_list, type)
  assessment_hash = make_assessment_hash
  assessment_hash[:total] = rule_target_list.count
  assessment_hash[:threshold] = THRESHOLDS[type]

  unless rule_target_list.empty?
    score = rule_target_list.first.score
    location = rule_target_list.first.location
    assessment_hash[:min] = score
    assessment_hash[:min_file] = location
    assessment_hash[:max] = score
    assessment_hash[:max_file] = location
  end
  assessment_hash
end

.load_summary_data(summary_hash) ⇒ Object

Returns a CukeSniffer::SummaryNode object for the passed hash



79
80
81
82
83
84
85
86
87
88
# File 'lib/cuke_sniffer/summary_helper.rb', line 79

def self.load_summary_data(summary_hash)
  summary_node = SummaryNode.new
  summary_node.count = summary_hash[:total]
  summary_node.score = summary_hash[:total_score]
  summary_node.average = summary_hash[:average]
  summary_node.threshold = summary_hash[:threshold]
  summary_node.good = summary_hash[:good]
  summary_node.bad = summary_hash[:bad]
  summary_node
end

.make_assessment_hashObject

Builds a default assessment hash.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cuke_sniffer/summary_helper.rb', line 21

def self.make_assessment_hash
  {
      :total => 0,
      :total_score => 0,
      :min => nil,
      :min_file => nil,
      :max => nil,
      :max_file => nil,
      :average => 0,
      :threshold => nil,
      :good => 0,
      :bad => 0,
      :improvement_list => {}
  }
end

.sort_improvement_list(improvement_list) ⇒ Object

Sorts the list of improvements in descending order of times found.



11
12
13
14
15
16
17
18
# File 'lib/cuke_sniffer/summary_helper.rb', line 11

def self.sort_improvement_list(improvement_list)
  sorted_array = improvement_list.sort_by { |improvement, occurrence| occurrence }.reverse
  sorted_improvement_list = {}
  sorted_array.each { |node|
    sorted_improvement_list[node[0]] = node[1]
  }
  sorted_improvement_list
end