class RuboCop::AST::RegexpNode
A node extension for `regexp` nodes. This will be used in place of a plain node when the builder constructs the AST
, making its methods available to all `regexp` nodes within RuboCop
.
Constants
- OPTIONS
Public Instance Methods
@return [String] a string of regexp content
# File lib/rubocop/ast/node/regexp_node.rb, line 36 def content children.select(&:str_type?).map(&:str_content).join end
@return [Bool] if char is one of the delimiters
# File lib/rubocop/ast/node/regexp_node.rb, line 56 def delimiter?(char) delimiters.include?(char) end
@return [String] the regexp delimiters (without %r)
# File lib/rubocop/ast/node/regexp_node.rb, line 51 def delimiters [loc.begin.source[-1], loc.end.source[0]] end
@return [Bool] if regexp uses the extended regopt
# File lib/rubocop/ast/node/regexp_node.rb, line 71 def extended? regopt_include?(:x) end
@return [Bool] if regexp uses the ignore-case regopt
# File lib/rubocop/ast/node/regexp_node.rb, line 76 def ignore_case? regopt_include?(:i) end
@return [Bool] if regexp contains interpolation
# File lib/rubocop/ast/node/regexp_node.rb, line 61 def interpolation? children.any?(&:begin_type?) end
@return [Bool] if regexp uses the multiline regopt
# File lib/rubocop/ast/node/regexp_node.rb, line 66 def multiline_mode? regopt_include?(:m) end
@return [Bool] if regexp uses the no-encoding regopt
# File lib/rubocop/ast/node/regexp_node.rb, line 86 def no_encoding? regopt_include?(:n) end
NOTE: The 'o' option is ignored.
@return [Integer] the Regexp option bits as returned by Regexp#options
# File lib/rubocop/ast/node/regexp_node.rb, line 31 def options regopt.children.map { |opt| OPTIONS.fetch(opt) }.inject(0, :|) end
@return [Bool] if the regexp is a %r{…} literal (using any delimiters)
# File lib/rubocop/ast/node/regexp_node.rb, line 46 def percent_r_literal? !slash_literal? end
@return [RuboCop::AST::Node] a regopt node
# File lib/rubocop/ast/node/regexp_node.rb, line 24 def regopt children.last end
@return [Bool] if regexp uses the single-interpolation regopt
# File lib/rubocop/ast/node/regexp_node.rb, line 81 def single_interpolation? regopt_include?(:o) end
@return [Bool] if the regexp is a /…/ literal
# File lib/rubocop/ast/node/regexp_node.rb, line 41 def slash_literal? loc.begin.source == '/' end
@return [Regexp] a regexp of this node
# File lib/rubocop/ast/node/regexp_node.rb, line 19 def to_regexp Regexp.new(content, options) end
Private Instance Methods
# File lib/rubocop/ast/node/regexp_node.rb, line 92 def regopt_include?(option) regopt.children.include?(option) end