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)


95
96
97
# File 'lib/epuber/checker/text_checker.rb', line 95

def file_path
  @file_path
end

#textString

Returns:

  • (String)


91
92
93
# File 'lib/epuber/checker/text_checker.rb', line 91

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



105
106
107
108
109
110
111
112
113
# File 'lib/epuber/checker/text_checker.rb', line 105

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

#should_not_contain(regexp, message) ⇒ Object

Parameters:

  • regexp (Regexp)
  • message (String)

    message to display, when the regexp found something



118
119
120
121
122
123
124
125
126
# File 'lib/epuber/checker/text_checker.rb', line 118

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.print_processing_problem MatchProblem.new(match, message, Config.instance.pretty_path_from_project(file_path))
  end
end