Class: Epuber::Checker::TextChecker

Inherits:
Epuber::Checker show all
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

Methods inherited from Epuber::Checker

map_source_type__class

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_pathString

Returns:

  • (String)


35
36
37
# File 'lib/epuber/checker/text_checker.rb', line 35

def file_path
  @file_path
end

#textString

Returns:

  • (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.

Parameters:

  • file_path (String)
  • text (String)
  • compilation_context (CompilationContext)

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(message, location: nil)
  super(message, location: location || Config.instance.pretty_path_from_project(file_path))
end

#should_not_contain(regexp, message) ⇒ Object

Parameters:

  • regexp (Regexp)
  • message (String)

    message to display, when the regexp found something



58
59
60
61
62
63
64
65
66
# File 'lib/epuber/checker/text_checker.rb', line 58

def should_not_contain(regexp, message)
  # 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, message, 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(message, location: nil)
  super(message, location: location || Config.instance.pretty_path_from_project(file_path))
end