Class: DoubleQuotedTextNode

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
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?

Methods included from NodeProcessing

#flatten

Methods included from BaseNode

#shatter?, #shattered_node_list

Instance Method Details

#elementsObject



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

Returns:

  • (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

#leavesObject



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_elementsObject



17
# File 'lib/core/double_quoted_text_node.rb', line 17

alias :original_elements :elements

#original_text_valueObject



18
# File 'lib/core/double_quoted_text_node.rb', line 18

alias :original_text_value :text_value

#text_valueObject



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_elementsObject



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