Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lambda support for XML -> Ruby conversion #14

Open
yob opened this issue Oct 27, 2009 · 0 comments
Open

lambda support for XML -> Ruby conversion #14

yob opened this issue Oct 27, 2009 · 0 comments

Comments

@yob
Copy link
Contributor

yob commented Oct 27, 2009

For reference, the Product class in my ONIX library: http://github.com/yob/onix/blob/master/lib/onix/product.rb, lines 31-37.

The ONIX spec requires all dates to be formatted as YYYYMMDD.

I handle the to_xml conversion from a Date class to a string by defining a lambda method and passing it to the attribute using the :to_xml option.

For marshalling xml strings into Date objects, I was using ":as => Date", but that would raise an exception when I tried to parse a file that containing invalid dates ( like "00000000"). To define my own XML->Ruby process, I have to pass a block into the attribute definition. This works, but has lead to some duplication.

It would be awesome if I could pass a lambda object into :as, just like I can with :to_xml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant