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
talon_one-2.0.0 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/regexp_node.rb
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/regexp_node.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/ast/node/regexp_node.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/ast/node/regexp_node.rb
rubocop-0.79.0 lib/rubocop/ast/node/regexp_node.rb
rubocop-0.78.0 lib/rubocop/ast/node/regexp_node.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/ast/node/regexp_node.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/ast/node/regexp_node.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/ast/node/regexp_node.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/ast/node/regexp_node.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/ast/node/regexp_node.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/ast/node/regexp_node.rb
rubocop-0.77.0 lib/rubocop/ast/node/regexp_node.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/ast/node/regexp_node.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/ast/node/regexp_node.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/ast/node/regexp_node.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/ast/node/regexp_node.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/ast/node/regexp_node.rb
rubocop-0.76.0 lib/rubocop/ast/node/regexp_node.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/ast/node/regexp_node.rb