Date: 2007-01-03 20:31
Sender: Walter Korman
I hit this issue as well. It's a showstopper for folks looking
to use this library, so it'd be nice to see it fixed. I'll have
to manually patch for now. :-)
Here is an improved patch (IMO) that ensures all values are safely
obtained, avoiding nil exceptions, and also cleans up the code
for parsing URIs and Time values.
I can't find where the source is in svn/cvs, so just diffed locally
against the unmodified gem code.
44,51c44,51
< result.title = r.elements['Title'].text
< result.summary = r.elements['Summary'].text
< result.url = URI.parse
r.elements['Url'].text
< result.click_url = URI.parse
r.elements['ClickUrl'].text
< result.mime_type
= r.elements['MimeType'].text
< result.modification_date = Time.at
r.elements['ModificationDate'].text.to_i
< result.cache_url = URI.parse
r.elements['Cache/Url'].text
< result.cache_size
= r.elements['Cache/Size'].text.to_i
---
> result.title = _safe_value(r, 'Title')
> result.summary = _safe_value(r, 'Summary')
> result.url = _safe_value(r, 'Url',
'to_uri')
> result.click_url = _safe_value(r, 'ClickUrl')
> result.mime_type = _safe_value(r, 'MimeType')
> result.modification_date = _safe_value(r,
'ModificationDate', 'to_time')
> result.cache_url = _safe_value(r, 'Cache/Url',
'to_uri')
> result.cache_size = _safe_value(r, 'Cache/Size',
'to_i')
59a60,73
> protected
>
> def _safe_value (element, key, format = 'to_s')
> value = element.elements[key]
> return nil if value.nil?
>
> text = value.text
> case format
> when 'to_uri' then URI.parse(text)
> when 'to_time' then Time.at(text.to_i)
> else text.send(format)
> end
> end
>
|