Created
June 2, 2012 21:11
-
-
Save solomon081/2859964 to your computer and use it in GitHub Desktop.
RBHTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def strpush! push | |
newstring = push + self | |
self.replace(newstring) | |
end | |
end | |
class HTMLDocument | |
private | |
def refresh_full | |
@full_doc = @open_doc + @close_doc | |
end | |
public | |
def initialize | |
@open_doc = "<html><body>" | |
@close_doc = "</body></html>" | |
@full_doc = @open_doc + @close_doc | |
end | |
def create_element tag, inner | |
@open_doc += "<#{tag}>#{inner}" | |
@close_doc.strpush!("</#{tag}>") | |
refresh_full | |
end | |
def remove_element tag, inner | |
@open_doc.gsub!("<#{tag}>#{inner}", "") | |
@close_doc.gsub!("</#{tag}>", "") | |
refresh_full | |
end | |
def remove_char char | |
@open_doc.gsub!(">#{char}", ">") | |
refresh_full | |
end | |
def to_s | |
@full_doc | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment