Class: CukeSniffer::RuleTarget

Inherits:
Object
  • Object
show all
Includes:
Constants, RuleConfig, ROXML
Defined in:
lib/cuke_sniffer/rule_target.rb

Overview

Author

Robert Cochran ([email protected])

Copyright

Copyright © 2013 Robert Cochran

License

Distributes under the MIT License

Parent class for all objects that have rules executed against it Mixins: CukeSniffer::Constants, CukeSniffer::RuleConfig, ROXML

Direct Known Subclasses

FeatureRuleTarget, Hook, StepDefinition

Constant Summary

Constants included from RuleConfig

CukeSniffer::RuleConfig::ERROR, CukeSniffer::RuleConfig::FATAL, CukeSniffer::RuleConfig::INFO, CukeSniffer::RuleConfig::RULES, CukeSniffer::RuleConfig::WARNING

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ RuleTarget

Location must be in the format of “file_pathfile_name.rb:line_number”



29
30
31
32
33
34
# File 'lib/cuke_sniffer/rule_target.rb', line 29

def initialize(location)
  @location = location
  @score = 0
  @rules_hash = {}
  @class_type = self.class.to_s.gsub(/.*::/, "")
end

Instance Attribute Details

#locationObject

string: Location in which the object was found



21
22
23
# File 'lib/cuke_sniffer/rule_target.rb', line 21

def location
  @location
end

#rules_hashObject

hash: Contains the phrase every rule fired against the object and times it fired

  • Key: string

  • Value: int



26
27
28
# File 'lib/cuke_sniffer/rule_target.rb', line 26

def rules_hash
  @rules_hash
end

#scoreObject

int: Sum of the rules fired



18
19
20
# File 'lib/cuke_sniffer/rule_target.rb', line 18

def score
  @score
end

Instance Method Details

#==(comparison_object) ⇒ Object

:nodoc:



49
50
51
52
53
# File 'lib/cuke_sniffer/rule_target.rb', line 49

def == (comparison_object) # :nodoc:
  comparison_object.location == location &&
  comparison_object.score == score &&
  comparison_object.rules_hash == rules_hash
end

#good?Boolean

Compares the score against the objects threshold If a score is below the threshold it is good and returns true Return: Boolean



39
40
41
# File 'lib/cuke_sniffer/rule_target.rb', line 39

def good?
  score <= Constants::THRESHOLDS[@class_type]
end

#problem_percentageObject

Calculates the score to threshold percentage of an object Return: Float



45
46
47
# File 'lib/cuke_sniffer/rule_target.rb', line 45

def problem_percentage
  score.to_f / Constants::THRESHOLDS[@class_type].to_f
end