Module: TextNode

Instance Method Summary collapse

Methods included from NodeProcessing

#flatten

Methods included from BaseNode

#shatter?, #shattered_node_list

Instance Method Details

#amount_of_ending_whitespaceObject



44
45
46
# File 'lib/core/text_node.rb', line 44

def amount_of_ending_whitespace
  self.text_value.length - self.text_value.rstrip.length    
end

#amount_of_starting_whitespaceObject



48
49
50
# File 'lib/core/text_node.rb', line 48

def amount_of_starting_whitespace
  self.text_value.length - self.text_value.lstrip.length    
end

#contains_alpha_characters?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/core/text_node.rb', line 39

def contains_alpha_characters?
  !self.text_value[/[a-zA-Z]/].nil?
end

#extract_text(text_extractor, node_tree) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/core/text_node.rb', line 5

def extract_text( text_extractor, node_tree )
  if( self.strip_whitespace? && self.has_leading_or_trailing_whitespace? )
    self.remove_leading_and_trailing_whitespace.each do |node|
      node.extract_text( text_extractor, node_tree )
    end
  else
    text_extractor.add_html_text( self )
  end
end

#has_leading_or_trailing_whitespace?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/core/text_node.rb', line 52

def has_leading_or_trailing_whitespace?
  amount_of_ending_whitespace > 0 || amount_of_starting_whitespace > 0
end

#has_variables?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/core/text_node.rb', line 15

def has_variables?
  false
end

#html?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/core/text_node.rb', line 19

def html?
  true
end

#remove_leading_and_trailing_whitespaceObject

This probably won’t work, because I want it to retain all of the nodes. Maybe we should run this after the text extraction happens? Nope, that won’t work.…



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/core/text_node.rb', line 59

def remove_leading_and_trailing_whitespace
  to_return = []
  if( self.text_value.strip.empty? ) # is this only whitespace
    to_return << HerbWhiteSpaceTextNode.new( self.text_value )
  else # otherwise it has some text
    if( amount_of_starting_whitespace > 0 )
      to_return << HerbWhiteSpaceTextNode.new( self.text_value[0..(amount_of_starting_whitespace - 1 )] )
    end
    to_return << HerbTextNode.new( self.text_value.strip )
    if( amount_of_ending_whitespace > 0 )
      to_return << HerbWhiteSpaceTextNode.new( self.text_value[(self.text_value.length - amount_of_ending_whitespace)..self.text_value.length ])
    end
  end

  to_return
end

#strip_whitespace?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/core/text_node.rb', line 23

def strip_whitespace?
  true
end

#text?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/core/text_node.rb', line 27

def text?
  true
end

#top_level?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/core/text_node.rb', line 31

def top_level?
  true
end

#white_space?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/core/text_node.rb', line 35

def white_space?
  false
end