class RuboCop::AST::RegexpNode
to all ‘regexp` nodes within RuboCop.
node when the builder constructs the AST, making its methods available
A node extension for `regexp` nodes. This will be used in place of a plain
def content
-
(String)
- a string of regexp content
def content children.select(&:str_type?).map(&:str_content).join end
def delimiter?(char)
-
(Bool)
- if char is one of the delimiters
def delimiter?(char) delimiters.include?(char) end
def delimiters
-
(String)
- the regexp delimiters (without %r)
def delimiters [loc.begin.source[-1], loc.end.source[0]] end
def extended?
-
(Bool)
- if regexp uses the extended regopt
def extended? regopt_include?(:x) end
def ignore_case?
-
(Bool)
- if regexp uses the ignore-case regopt
def ignore_case? regopt_include?(:i) end
def interpolation?
-
(Bool)
- if regexp contains interpolation
def interpolation? children.any?(&:begin_type?) end
def multiline_mode?
-
(Bool)
- if regexp uses the multiline regopt
def multiline_mode? regopt_include?(:m) end
def no_encoding?
-
(Bool)
- if regexp uses the no-encoding regopt
def no_encoding? regopt_include?(:n) end
def percent_r_literal?
-
(Bool)
- if the regexp is a %r{...} literal (using any delimiters)
def percent_r_literal? !slash_literal? end
def regopt
-
(RuboCop::AST::Node)
- a regopt node
def regopt children.last end
def regopt_include?(option)
def regopt_include?(option) regopt.children.include?(option) end
def single_interpolation?
-
(Bool)
- if regexp uses the single-interpolation regopt
def single_interpolation? regopt_include?(:o) end
def slash_literal?
-
(Bool)
- if the regexp is a /.../ literal
def slash_literal? loc.begin.source == '/' end
def to_regexp
-
(Regexp)
- a regexp of this node
def to_regexp option = regopt.children.map { |opt| OPTIONS.fetch(opt) }.inject(:|) Regexp.new(content, option) end