Class: Ruber::ProjectFilesRuleChooser::RegexpRuleValidator

Inherits:
Qt::Validator
  • Object
show all
Defined in:
lib/ruber/world/project_files_widget.rb

Overview

Validator class for regexp rules

It marks the text as @Qt::Validator::Intermediate@ if a valid regexp can’t be constructed from it and as @Qt::Validator::Acceptable@ if it can

Instance Method Summary collapse

Instance Method Details

#validate(input, _pos) ⇒ Integer

Override of @Qt::Validator#validate@

Parameters:

  • input (String)

    the text in the widget

  • _pos (Integer)

    the cursor position (unused)

Returns:

  • (Integer)

    @Qt::Validator::Acceptable@ if the text is a valid regexp and @Qt::Validator::Intermediate@ otherwise



67
68
69
70
71
72
73
74
# File 'lib/ruber/world/project_files_widget.rb', line 67

def validate input, _pos
  begin 
    Regexp.new(input)
    Acceptable
  rescue RegexpError
    Intermediate
  end
end