 |
Forums |
Admin Start New Thread
By: Peter Szinek
RE: Turning the Extractor Data into a hash [ reply ] 2007-02-10 08:48
|
Thanks for the input, Ben! I really appreciate it.
ATM I am working on this (would this address your problem?):
Say you have an extractor like this:
amazon_books = ...define do
book do
author
price
end
end
then you can iterate over this with:
amazon_books.book.each do |b|
b.author.each {|a| puts a}
end
?
I am glad you like the framework - and the best is yet to come... what you have seen so far is just a sketch with lots of missing parts and rough details...
|
By: Ben Mabey
RE: Turning the Extractor Data into a hash [ reply ] 2007-02-09 17:58
|
Well, the reason I want it into a hash is so I can use enumerable and basically to whatever I need with it. By making it available into a hash people could do just about what ever they want to. For example, I didn't know how to follow the details links but I figured with a hash I could use each and run another extractor.. (btw, I saw your post about it though.)
Anyways, mapping XML to a hash is a very natural thing to do and the way ActiveResource does it is nice. So maybe that source would be a good reference.
I also saw this gem that takes a XML string and converts it into a hash. So I am using it as a roundabout way to get what I wanted. Here is the gem:
http://cobravsmongoose.rubyforge.org/
Here is the line to get it into a hash:
hash = CobraVsMongoose.xml_to_hash(the_extractor_data.to_xml)
It is a round about way and the hash but I guess it gets the job done. Although I don't like the output as much as Rails XML to Hash.
Anyways, thanks for all the work. I'm really liking the framework so far.
|
By: Peter Szinek
RE: Turning the Extractor Data into a hash [ reply ] 2007-02-09 10:39
|
ATM this is not possible - there is only XML and
amazon_books.book[4].title style output. However, in the future there will be tons of other types of output - I did not think about a hash yet.
How would you like it to look exactly? Could you provide an example?
|
By: Ben Mabey
Turning the Extractor Data into a hash [ reply ] 2007-02-09 10:11
|
What is the best way to convert the data gathered by an extractor into a hash? So you would have a hash representation of the XML document that gets spit out at the end.
Also, is there a way to follow certain links... So in the ebay example on the main scRUBYt page could you have it follow each details link and extract other product information from those pages?
Thanks.
-Ben
|
|
 |