Class: TFHppleElement

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-hpple/hpple.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



31
32
33
# File 'lib/motion-hpple/hpple.rb', line 31

def [](key)
  self.objectForKey(key)
end

#inner_htmlObject



46
47
48
49
50
# File 'lib/motion-hpple/hpple.rb', line 46

def inner_html
  return self.children.map do |sub_node|
    sub_node.to_html
  end.join
end

#inner_textObject



39
40
41
42
43
44
# File 'lib/motion-hpple/hpple.rb', line 39

def inner_text
  return self.content if self.content
  return self.children.collect do |sub_node|
    sub_node.inner_text
  end.join("")
end

#tagObject



27
28
29
# File 'lib/motion-hpple/hpple.rb', line 27

def tag
  self.tagName
end

#textObject



35
36
37
# File 'lib/motion-hpple/hpple.rb', line 35

def text
  self.inner_text
end

#to_htmlObject

a hack to return html



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/motion-hpple/hpple.rb', line 53

def to_html
  if self.content
    self.content
  else
    tags_fragments = []
    tags_fragments << "<#{self.tag}"
    self.attributes.each do |key, value|
      value = value.gsub('"', '&quot;')
      tags_fragments << "#{key}=\"#{value}\""
    end
    tags_fragments.join(" ") + ">" + self.inner_html + "</#{self.tag}>"
  end
end

#to_sObject



67
68
69
70
71
72
73
# File 'lib/motion-hpple/hpple.rb', line 67

def to_s
  if self.content
    self.content
  else
    self.inner_text
  end
end