Class: CukeSniffer::RuleTarget
- Inherits:
-
Object
- Object
- CukeSniffer::RuleTarget
- Includes:
- Constants, RuleConfig, ROXML
- Defined in:
- lib/cuke_sniffer/rule_target.rb
Overview
- Author
-
Robert Cochran ([email protected])
- Copyright
-
Copyright © 2014 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
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
-
#location ⇒ Object
string: Location in which the object was found.
-
#rules_hash ⇒ Object
hash: Contains the phrase every rule fired against the object and times it fired * Key: string * Value: int.
-
#score ⇒ Object
int: Sum of the rules fired.
-
#type ⇒ Object
string: Type of the object being evaluated.
Instance Method Summary collapse
-
#==(comparison_object) ⇒ Object
:nodoc:.
-
#good? ⇒ Boolean
Compares the score against the objects threshold If a score is below the threshold it is good and returns true Return: Boolean.
-
#initialize(location) ⇒ RuleTarget
constructor
Location must be in the format of “file_pathfile_name.rb:line_number”.
-
#is_comment?(line) ⇒ Boolean
TODO Abstraction needed for this regex matcher (constants?).
-
#problem_percentage ⇒ Object
Calculates the score to threshold percentage of an object Return: Float.
- #store_rule(rule, phrase = rule.phrase) ⇒ Object
- #store_rule_many_times(rule, count, phrase = rule.phrase) ⇒ Object
Constructor Details
#initialize(location) ⇒ RuleTarget
Location must be in the format of “file_pathfile_name.rb:line_number”
35 36 37 38 39 40 |
# File 'lib/cuke_sniffer/rule_target.rb', line 35 def initialize(location) @location = location @score = 0 @rules_hash = {} @class_type = self.class.to_s.gsub(/.*::/, "") end |
Instance Attribute Details
#location ⇒ Object
string: Location in which the object was found
24 25 26 |
# File 'lib/cuke_sniffer/rule_target.rb', line 24 def location @location end |
#rules_hash ⇒ Object
hash: Contains the phrase every rule fired against the object and times it fired
-
Key: string
-
Value: int
29 30 31 |
# File 'lib/cuke_sniffer/rule_target.rb', line 29 def rules_hash @rules_hash end |
#score ⇒ Object
int: Sum of the rules fired
21 22 23 |
# File 'lib/cuke_sniffer/rule_target.rb', line 21 def score @score end |
#type ⇒ Object
string: Type of the object being evaluated
32 33 34 |
# File 'lib/cuke_sniffer/rule_target.rb', line 32 def type @type end |
Instance Method Details
#==(comparison_object) ⇒ Object
:nodoc:
55 56 57 58 59 |
# File 'lib/cuke_sniffer/rule_target.rb', line 55 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
45 46 47 |
# File 'lib/cuke_sniffer/rule_target.rb', line 45 def good? score <= Constants::THRESHOLDS[@class_type] end |
#is_comment?(line) ⇒ Boolean
TODO Abstraction needed for this regex matcher (constants?)
62 63 64 |
# File 'lib/cuke_sniffer/rule_target.rb', line 62 def is_comment?(line) true if line =~ /^\#.*$/ end |
#problem_percentage ⇒ Object
Calculates the score to threshold percentage of an object Return: Float
51 52 53 |
# File 'lib/cuke_sniffer/rule_target.rb', line 51 def problem_percentage score.to_f / Constants::THRESHOLDS[@class_type].to_f end |
#store_rule(rule, phrase = rule.phrase) ⇒ Object
66 67 68 69 70 |
# File 'lib/cuke_sniffer/rule_target.rb', line 66 def store_rule(rule, phrase = rule.phrase) @score += rule.score @rules_hash[phrase] ||= 0 @rules_hash[phrase] += 1 end |
#store_rule_many_times(rule, count, phrase = rule.phrase) ⇒ Object
72 73 74 75 76 |
# File 'lib/cuke_sniffer/rule_target.rb', line 72 def store_rule_many_times(rule, count, phrase = rule.phrase) count.times do store_rule(rule, phrase) end end |