Sha256: a686ebaf9b20b3131461c74bcb9406eef69fe622345441c8af48d5a4eeba1eb9

Contents?: true

Size: 938 Bytes

Versions: 6881

Compression:

Stored size: 938 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module AST
    # 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.
    class RegexpNode < Node
      OPTIONS = {
        x: Regexp::EXTENDED,
        i: Regexp::IGNORECASE,
        m: Regexp::MULTILINE,
        n: Regexp::NOENCODING
      }.freeze

      # @return [Regexp] a regexp of this node
      def to_regexp
        option = regopt.children.map { |opt| OPTIONS[opt] }.inject(:|)
        Regexp.new(content, option)
      end

      # @return [RuboCop::AST::Node] a regopt node
      def regopt
        first, second = *self
        first.regopt_type? ? first : second
      end

      # @return [String] a string of regexp content
      def content
        str = children.first
        str.str_content || ''
      end
    end
  end
end

Version data entries

6,881 entries across 6,856 versions & 28 rubygems

Version Path
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/ast/node/regexp_node.rb
rubocop-0.72.0 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.71.0 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.70.0 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.69.0 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.68.1 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.68.0 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.67.2 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.67.1 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.67.0 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.66.0 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.65.0 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.64.0 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.63.1 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.63.0 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.62.0 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.61.1 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.61.0 lib/rubocop/ast/node/regexp_node.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/ast/node/regexp_node.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/ast/node/regexp_node.rb