phil swenson
10/12/2006 3:54:00 AM
small_image_url = XPath.first(item, "SmallImage/URL").text
small_image_height = XPath.first(item, "SmallImage/Height
Units").text
small_image_width = XPath.first(item, "SmallImage/Width
Units").text
medium_image_url = XPath.first(item, "MediumImage/URL").text
medium_image_height = XPath.first(item, "MediumImage/Height
Units").text
medium_image_width = XPath.first(item, "MediumImage/Width
Units").text
large_image_url = XPath.first(item, "LargeImage/URL").text
large_image_height = XPath.first(item, "LargeImage/Height
Units").text
large_image_width = XPath.first(item, "LargeImage/Width
Units").text
Instead of writing this with this redundant style, how would a clever
rubyist write this? Could write a method to take the image name as an
input and return 3 params...
def image_attributes (item, image_name)
height = XPath.first(item, image_name + "/Height Units").text
width = XPath.first(item, image_name + "/Width Units").text
url = XPath.first(item, image_name + "/URL").text
return height, width, url
end
small_image_height, small_image_width, small_image_url =
image_attributes(item, "SmallImage")
medium_image_height, medium_image_width, medium_image_url =
image_attributes(item, "MediumImage")
large_image_height, large_image_width, large_image_url =
image_attributes(item, "LargeImage")
However, I'm thinking there are much nicer ways to do it...
any thoughts?