Class: DoubleQuotedTextNode
- Inherits:
-
Treetop::Runtime::SyntaxNode
- Object
- Treetop::Runtime::SyntaxNode
- DoubleQuotedTextNode
show all
- Includes:
- TextNode
- Defined in:
- lib/core/double_quoted_text_node.rb
Instance Method Summary
collapse
Methods included from TextNode
#amount_of_ending_whitespace, #amount_of_starting_whitespace, #contains_alpha_characters?, #extract_text, #has_leading_or_trailing_whitespace?, #html?, #remove_leading_and_trailing_whitespace, #strip_whitespace?, #text?, #top_level?, #white_space?
#flatten
Methods included from BaseNode
#shatter?, #shattered_node_list
Instance Method Details
#elements ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/core/double_quoted_text_node.rb', line 20
def elements
if( has_variables? )
strip_leading_and_trailing_double_quotes( variable_elements )
else
strip_leading_and_trailing_double_quotes( original_elements )
end
end
|
#has_variables? ⇒ Boolean
5
6
7
|
# File 'lib/core/double_quoted_text_node.rb', line 5
def has_variables?
leaves.any? { |node| node.is_a?( HerbStringVariable ) }
end
|
#leaves ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/core/double_quoted_text_node.rb', line 9
def leaves
leaves_to_return = []
original_elements.each do |element|
leaves_to_return += flatten element
end unless original_elements.nil? || original_elements.empty?
leaves_to_return
end
|
#original_elements ⇒ Object
17
|
# File 'lib/core/double_quoted_text_node.rb', line 17
alias :original_elements :elements
|
#original_text_value ⇒ Object
18
|
# File 'lib/core/double_quoted_text_node.rb', line 18
alias :original_text_value :text_value
|
#text_value ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/core/double_quoted_text_node.rb', line 28
def text_value
if( has_variables? )
elements.inject('') { |string, current_element| string += current_element.text_value }
else
original_text_value
end
end
|
#variable_elements ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/core/double_quoted_text_node.rb', line 37
def variable_elements
found_elements = []
current_text = ''
leaves.each do |leaf|
if( leaf.is_a?( HerbStringVariable ) )
found_elements = add_text_to_array( found_elements, current_text )
current_text = ''
found_elements << leaf
else
current_text += leaf.text_value unless( leaf.nil? || leaf.text_value.empty? )
end
end
found_elements = add_text_to_array( found_elements, current_text )
found_elements
end
|