Sha256: d90610acdd038d98635c3142042fd7576a6cf43a6b1b3d2c269c9dfa06612d69
Contents?: true
Size: 1.48 KB
Versions: 1
Compression:
Stored size: 1.48 KB
Contents
# frozen_string_literal: true module RuboCop module AST # A node extension for `str`, `dstr`, and `xstr` nodes. This will be used # in place of a plain node when the builder constructs the AST, making # its methods available to all `str` nodes within RuboCop. class StrNode < Node include BasicLiteralNode PERCENT_LITERAL_TYPES = { :% => /\A%(?=[^a-zA-Z])/, :q => /\A%q/, :Q => /\A%Q/ }.freeze def single_quoted? loc_is?(:begin, "'") end def double_quoted? loc_is?(:begin, '"') end def character_literal? loc_is?(:begin, '?') end def heredoc? loc.is_a?(Parser::Source::Map::Heredoc) end # Checks whether the string literal is delimited by percent brackets. # # @overload percent_literal? # Check for any string percent literal. # # @overload percent_literal?(type) # Check for a string percent literal of type `type`. # # @param type [Symbol] an optional percent literal type # # @return [Boolean] whether the string is enclosed in percent brackets def percent_literal?(type = nil) opening_delimiter = loc.begin if loc.respond_to?(:begin) return false unless opening_delimiter if type opening_delimiter.source.match?(PERCENT_LITERAL_TYPES.fetch(type)) else opening_delimiter.source.start_with?('%') end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rubocop-ast-1.37.0 | lib/rubocop/ast/node/str_node.rb |