viernes, 26 de julio de 2013

Andando, que es gerundio

Andando, que es gerundio

Quizá a alguien se le ocurra alguna representación mejor para los datos. Seguro que sí. Pero eso es lo bueno que tiene la programación orientada a objetos: más adelante podríamos cambiar como funcionan nuestros “HtmlDocs” por dentro y, mientras mantengamos las mismas interfaces públicas, externas, no sería necesario modificar el resto de nuestras aplicaciones.

Comencemos por definir la parte visible de nuestra clase. Únicamente sus métodos públicos vacíos, como viene siendo costumbre. Que nadie se preocupe, que más adelante los rellenamos:

require File.dirname(__FILE__) + '/htmlparser.rb'
# Class for HTML Document and object management
# HTML Docs keep track of nodes created from them
# nodes with HTML elements can be managed just like documents

  
class HtmlDoc
# Object creation
def initialize(html=nil)
end

###################
# Node information
###################

# Returns the type of the Html Doc/Node object
def typeOf
end


# Name of the tag represented by the object
def tagName
end
# Hash of attributes of the element represented by the object
def attributes
end

###########################
# HTML and Text extraction
###########################

# HTML code for the object, including its own tags
def outerHTML
end

# to_s is just another alias for outerHTML
alias_method :to_s, :outerHTML

# HTML code for the object, excluding its own tags
def innerHTML
end


#############
# Attributes
#############

# Get attribute value
def [](index)
end

# Set attribute value
def []=(index, value)
end

################################
# Element search and navigation
################################

# Get a element, given its Id
def getElementById(id)
end

# Get an array of elements with a given tag name
def getElementsByTagName(thetagname)
end


# Array of elements with an given attribute being equal to a given value
def getElementsByAttribute(attribute, value)
end

# Array of child nodes for an element
def children
end


#############################
# Document/Node manipulation
#############################

# Delete current node from document
def removeFromDocument
end

# Change innerHTML for an element. Doesn't modify the element itself,
# but the ones inside of it.
def changeInnerHTML(html)
end

# Insert HTML before a node
def insertBefore(html)
end

# Insert HTML after a node
def insertAfter(html)
end
end

Guardemos esto en nuestra carpeta de siempre con el nombre “htmldoc.rb”.

Ya nos hemos puesto en marcha.

Continuará...

No hay comentarios:

Publicar un comentario