Class: SyntaxTree::StringContent
Overview
StringContent represents the contents of a string-like value.
"string"
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#parts ⇒ Object
readonly
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the string.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(parts: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parts:, location:) ⇒ StringContent
constructor
A new instance of StringContent.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(parts:, location:) ⇒ StringContent
Returns a new instance of StringContent.
10011 10012 10013 10014 10015 |
# File 'lib/syntax_tree/node.rb', line 10011 def initialize(parts:, location:) @parts = parts @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10009 10010 10011 |
# File 'lib/syntax_tree/node.rb', line 10009 def comments @comments end |
#parts ⇒ Object (readonly)
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the
string
10006 10007 10008 |
# File 'lib/syntax_tree/node.rb', line 10006 def parts @parts end |
Instance Method Details
#===(other) ⇒ Object
10038 10039 10040 |
# File 'lib/syntax_tree/node.rb', line 10038 def ===(other) other.is_a?(StringContent) && ArrayMatch.call(parts, other.parts) end |
#accept(visitor) ⇒ Object
10017 10018 10019 |
# File 'lib/syntax_tree/node.rb', line 10017 def accept(visitor) visitor.visit_string_content(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
10021 10022 10023 |
# File 'lib/syntax_tree/node.rb', line 10021 def child_nodes parts end |
#copy(parts: nil, location: nil) ⇒ Object
10025 10026 10027 10028 10029 10030 |
# File 'lib/syntax_tree/node.rb', line 10025 def copy(parts: nil, location: nil) StringContent.new( parts: parts || self.parts, location: location || self.location ) end |
#deconstruct_keys(_keys) ⇒ Object
10034 10035 10036 |
# File 'lib/syntax_tree/node.rb', line 10034 def deconstruct_keys(_keys) { parts: parts, location: location } end |
#format(q) ⇒ Object
10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 |
# File 'lib/syntax_tree/node.rb', line 10042 def format(q) q.text(q.quote) q.group do parts.each do |part| if part.is_a?(TStringContent) value = Quotes.normalize(part.value, q.quote) first = true value.each_line(chomp: true) do |line| if first first = false else q.breakable_return end q.text(line) end q.breakable_return if value.end_with?("\n") else q.format(part) end end end q.text(q.quote) end |