--------------020808070807060205090301
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Robert Klemme wrote:
snip
=> #<Date: 4906577/2,0,2299161>
What did you do?
That's my question. And I think I found it: If I do class Article
include REXML ... ... end
I get the error with strptime.
If I use REXML:
ocument and don't include, then everything is fine.
So REXML does something to Date.
I run ruby 1.8.2 (2004-12-25) [i386-mswin32]
Since I cannot duplicate the problem in irb with a simple include,
here's the code that duplicates this, maybe someone can see what's wrong.
Cheers,
V.-
____________________________________________________________________
http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.freemail.gr - free email service for the Greek-speaking.
--------------020808070807060205090301
Content-Type: text/xml;name="example.xml"
Content-Disposition: inline;filename="example.xml"
Content-Transfer-Encoding: quoted-printable
=EF=BB=BF<article>
<title>Title</title>
<date>10.05.06</date>
<language>el</language>
<text>Some text in UTF8, =CF=87=CE=B5=CF=87=CE=B5=CF=87=CE=AD</text>
</article>
--------------020808070807060205090301
Content-Type: text/plain;name="test.rb"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;filename="test.rb"
require 'rexml/document'
class Article
include REXML
ITEM_TITLE="title"
ITEM_CREATION="date"
ITEM_TEXT="text"
ITEM_LASTMODIFIED="lastmodified"
attr_reader :language,:text,:title,:created,:section,:filename,:last_modified
attr_writer :section
def initialize title,filename,text,creation_date,lastmodified="",language="el"
@title=title
@filename=filename
@text=text
@created=creation_date
@last_modified=last_modified
@language=language
@section=""
end
def to_s
return "#{@created} - #{@title}"
end
#Creates an Article instance from an XML file
#
# Raises BadArticleException if the file is malformed
def Article.generate filename
begin
xmldoc=Document.new( File.new(filename) )
filename=File.basename(filename).chomp(".xml")
title=xmldoc.root.elements[ITEM_TITLE].collect{|el|
el.to_s
}.join
date_txt=xmldoc.root.elements[ITEM_CREATION].text
#convert the date
begin
created=Date.strptime(date_txt,"%d.%m.%Y")
rescue ArgumentError
end
text=xmldoc.root.elements[ITEM_TEXT].collect{|el|
el.to_s
}.join
language="el"
lastmodified=created
begin
lastmodified_txt=xmldoc.root.elements[ITEM_LASTMODIFIED].text
if lastmodified_txt
begin
lastmodified=Date.strptime(lastmodified_txt,"%d.%m.%Y")
rescue ArgumentError
lastmodified=Date.new
end
end
end if xmldoc.root.elements[ITEM_LASTMODIFIED]
return Article.new(title,filename,text,created,lastmodified,language)
#rescue
# raise BadArticleException.new(filename,$!)
end
end
end
puts Article.generate("example.xml")
--------------020808070807060205090301--