Class: HTMLDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/rbhtml.rb

Instance Method Summary collapse

Constructor Details

#initializeHTMLDocument

Returns a new instance of HTMLDocument.



16
17
18
19
20
21
22
# File 'lib/rbhtml.rb', line 16

def initialize
  @open_doc = "<html><body>"
  @close_doc = "</body></html>"
  @full_doc = @open_doc + @close_doc
  @index_dict = {}
  @index_id = 0
end

Instance Method Details

#create_element(tag, inner, attribute = false, value = false) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/rbhtml.rb', line 23

def create_element tag, inner, attribute=false, value=false
  if attribute and value
    @open_doc += "<#{tag} #{attribute}='#{value}'>#{inner}</#{tag}>"
  else
    @open_doc += "<#{tag}>#{inner}</#{tag}>"
  end
  @index_id += 1
  refresh_full
  index_element tag, inner
end

#remove_char(char) ⇒ Object



38
39
40
41
# File 'lib/rbhtml.rb', line 38

def remove_char char
  @open_doc.gsub!(">#{char}", ">")
  refresh_full
end

#remove_element(tag, inner) ⇒ Object



33
34
35
36
37
# File 'lib/rbhtml.rb', line 33

def remove_element tag, inner
  @open_doc.gsub!("<#{tag}>#{inner}", "")
  @close_doc.gsub!("</#{tag}>", "")
  refresh_full
end

#to_sObject



42
43
44
# File 'lib/rbhtml.rb', line 42

def to_s
  @full_doc
end