Module: Prettyrb::Nodes::StringHelper

Included in:
DstrNode, RegexpNode, StrNode
Defined in:
lib/prettyrb/nodes/string_helper.rb

Constant Summary collapse

HEREDOC_TYPE_REGEX =
/<<([~-])?/

Instance Method Summary collapse

Instance Method Details

#closing_delimiterObject



18
19
20
# File 'lib/prettyrb/nodes/string_helper.rb', line 18

def closing_delimiter
  loc.expression.source.rstrip[-1]
end

#heredoc?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/prettyrb/nodes/string_helper.rb', line 38

def heredoc?
  !!loc.respond_to?(:heredoc_body)
end

#heredoc_bodyObject



34
35
36
# File 'lib/prettyrb/nodes/string_helper.rb', line 34

def heredoc_body
  loc.heredoc_body.source
end

#heredoc_identifierObject



22
23
24
# File 'lib/prettyrb/nodes/string_helper.rb', line 22

def heredoc_identifier
  loc.heredoc_end.source.strip
end

#heredoc_typeObject



26
27
28
29
30
31
32
# File 'lib/prettyrb/nodes/string_helper.rb', line 26

def heredoc_type
  # Always use indentable ending heredoc type if no type was provided
  #
  # eg: <<RUBY becomes <<-RUBY since <<- allows the ending identifier
  # to be indented
  loc.expression.source.match(HEREDOC_TYPE_REGEX)[1] || "-"
end

#percent_characterObject



10
11
12
# File 'lib/prettyrb/nodes/string_helper.rb', line 10

def percent_character
  loc.expression.source[1]
end

#percent_string?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/prettyrb/nodes/string_helper.rb', line 6

def percent_string?
  loc.expression.source.start_with?("%")
end

#start_delimiterObject



14
15
16
# File 'lib/prettyrb/nodes/string_helper.rb', line 14

def start_delimiter
  loc.expression.source[2]
end