[ruby-it] Help conversione PHP to Ruby
Alessandro Mazzone
mlafronte5 a hotmail.com
Ven 26 Dic 2008 16:59:09 CET
Salve,
avrei bisogno di un aiuto;premetto di essere un principiante nel campo
della programmazione,conosco un pò di C++ e mi è stato assegnato un
compito,nell'ambito di un progetto che sto facendo con l'uni.Devo
convertire un paio di classi di un programma open source da PHP a
Ruby,non conosco nessuno dei due linguaggi (sto studiandone un pò le
basi) e vorre qualche consiglio e aiuto,posto la classe più breve che
devo tradurre:
CODICE:
<?php
/**
* Progetto: XML Tree: Costruisce documenti XML<br>
* File: xml_tree.class.php<br>
*
* Descrizione:
* Aggiunge, toglie, legge, scrive file XML
*
* Versione PHP 5.1
*
* @category XML
* @package XMLTree
* @author Diego Brondo ~@:-] <jbrond a linuxmail.org>
* @copyright 2006
* @license http://www.php.net/license/3_01.txt PHP License v3.01
* @version 0.0.1
*/
if (!defined('__INCLUDE_PATH__'))
define('__INCLUDE_PATH__', './');
require_once(__INCLUDE_PATH__.'exceptions.class.php');
require_once(__INCLUDE_PATH__.'xml_parser.class.php');
class xml_tree extends xml_parser {
/** Indice nodo corrente
* @var int
* @access private
*/
private $_current = 0;
/** Castruttore
* @param mixed Percorso al file XML o Risorsa di file o stringa
contenente XML
* @param string Tipo di codifica
*/
function __construct($source, $charset=XML_CHARSET) {
parent::__construct($source, $charset);
}
/** Distruttore
*/
function __destruct() {
parent::__destruct();
}
/** Ottine il nodo root
* @return xml_element
*/
function get_root_node() {
return $this->_element_list;
}
/** Compie una ricerca all'interno di tutti gli elementi
* @param string Nome del tag da ricercare
* @param int Numero massimo di risultati (default illimitato)
* @param array Attributi che deve avere il nodo
* @return array
*/
function search($name, $limit=-1, $attrs=NULL) {
$ret = array();
if ($this->_element_list->get_name() == $name)
return $this->_element_list;
$i = 0;
$count = 0;
while ($node =& $this->_element_list->get_child($i++) && $count -
$limit != 0) {
$find = 0;
if (!strcmp($node->get_name(), $name))
$find = 1;
if (isset($attrs))
foreach($attrs as $k => $v)
$find &= $node->has_attribute($k, $v);
if ($find) {
$ret[] = $node;
$count++;
}
}
return $ret;
}
/** Rimpiazza un nodo con un altro
* @param xml_element Vecchio nodo
* @param xml_element Nuovo nodo
*/
function replace($old_node, $new_node) {
if (!is_object($old_node) || !is_object($new_node))
return 0;
if ($this->_element_list == $old_node)
$this->_element_list = $new_node;
$i = 0;
$continue = 1;
while ($node =& $this->_element_list->get_child($i++) &&
$continue) {
if ($node == $old_node) {
$continue = 0;
$node = $node->clona(&$new_node);
}
}
return 1;
}
/** Rimuove un nodo
* @param xml_element Vecchio nodo
*/
function remove($old_node) {
if (!is_object($old_node))
return 0;
if ($this->_element_list == $old_node)
$this->_element_list = array();
$i = 0;
$continue = 1;
while ($node =& $this->_element_list->get_child($i++) &&
$continue) {
if ($node == $old_node) {
$continue = 0;
$this->_element_list->del_child($i-1);
}
}
return 1;
}
}
// ~@:-]
?>
FINE CODICE
Le parti centrale e quella finale sono abbastanza semplici,il problema è
tradurre l'inizio ovvero queste 3-4 istruzioni:
if (!defined('__INCLUDE_PATH__'))
define('__INCLUDE_PATH__', './');
require_once(__INCLUDE_PATH__.'exceptions.class.php');
require_once(__INCLUDE_PATH__.'xml_parser.class.php');
Se qualcuno può darmi qualche dritta mi sarebbe molto utile,Grazie
--
Posted via http://www.ruby-forum.com/.
More information about the Ml
mailing list