Class: Epuber::Checker::TextChecker
- Inherits:
-
Epuber::Checker
- Object
- Epuber::CheckerTransformerBase
- Epuber::Checker
- Epuber::Checker::TextChecker
- Defined in:
- lib/epuber/checker/text_checker.rb
Defined Under Namespace
Classes: MatchProblem
Instance Attribute Summary collapse
Attributes inherited from Epuber::CheckerTransformerBase
#block, #options, #source_type
Instance Method Summary collapse
-
#call(file_path, text, compilation_context) ⇒ Object
Nil.
- #error(message, location: nil) ⇒ Object
- #should_not_contain(regexp, message) ⇒ Object
- #warning(message, location: nil) ⇒ Object
Methods inherited from Epuber::Checker
Methods inherited from Epuber::CheckerTransformerBase
class_for_source_type, #initialize, map_source_type__class, #valid_options
Constructor Details
This class inherits a constructor from Epuber::CheckerTransformerBase
Instance Attribute Details
#file_path ⇒ String
35 36 37 |
# File 'lib/epuber/checker/text_checker.rb', line 35 def file_path @file_path end |
#text ⇒ String
31 32 33 |
# File 'lib/epuber/checker/text_checker.rb', line 31 def text @text end |
Instance Method Details
#call(file_path, text, compilation_context) ⇒ Object
Returns nil.
45 46 47 48 49 50 51 52 53 |
# File 'lib/epuber/checker/text_checker.rb', line 45 def call(file_path, text, compilation_context) @file_path = file_path @text = text @block.call(self, text, compilation_context) @text = nil @file_path = nil end |
#error(message, location: nil) ⇒ Object
68 69 70 |
# File 'lib/epuber/checker/text_checker.rb', line 68 def error(, location: nil) super(, location: location || Config.instance.pretty_path_from_project(file_path)) end |
#should_not_contain(regexp, message) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/epuber/checker/text_checker.rb', line 58 def should_not_contain(regexp, ) # find all matches # taken from http://stackoverflow.com/questions/6804557/how-do-i-get-the-match-data-for-all-occurrences-of-a-ruby-regular-expression-in matches = text.to_enum(:scan, regexp).map { Regexp.last_match } matches.each do |match| # @type match [MatchData] UI.warning MatchProblem.new(match, , Config.instance.pretty_path_from_project(file_path)) end end |
#warning(message, location: nil) ⇒ Object
72 73 74 |
# File 'lib/epuber/checker/text_checker.rb', line 72 def warning(, location: nil) super(, location: location || Config.instance.pretty_path_from_project(file_path)) end |