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
- #closing_delimiter ⇒ Object
- #heredoc? ⇒ Boolean
- #heredoc_body ⇒ Object
- #heredoc_identifier ⇒ Object
- #heredoc_type ⇒ Object
- #percent_character ⇒ Object
- #percent_string? ⇒ Boolean
- #start_delimiter ⇒ Object
Instance Method Details
#closing_delimiter ⇒ Object
18 19 20 |
# File 'lib/prettyrb/nodes/string_helper.rb', line 18 def closing_delimiter loc.expression.source.rstrip[-1] end |
#heredoc? ⇒ Boolean
38 39 40 |
# File 'lib/prettyrb/nodes/string_helper.rb', line 38 def heredoc? !!loc.respond_to?(:heredoc_body) end |
#heredoc_body ⇒ Object
34 35 36 |
# File 'lib/prettyrb/nodes/string_helper.rb', line 34 def heredoc_body loc.heredoc_body.source end |
#heredoc_identifier ⇒ Object
22 23 24 |
# File 'lib/prettyrb/nodes/string_helper.rb', line 22 def heredoc_identifier loc.heredoc_end.source.strip end |
#heredoc_type ⇒ Object
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_character ⇒ Object
10 11 12 |
# File 'lib/prettyrb/nodes/string_helper.rb', line 10 def percent_character loc.expression.source[1] end |
#percent_string? ⇒ Boolean
6 7 8 |
# File 'lib/prettyrb/nodes/string_helper.rb', line 6 def percent_string? loc.expression.source.start_with?("%") end |
#start_delimiter ⇒ Object
14 15 16 |
# File 'lib/prettyrb/nodes/string_helper.rb', line 14 def start_delimiter loc.expression.source[2] end |