------art_18124_676102.1160626974424
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi-

On 10/11/06, phil.swenson / gmail.com <phil.swenson / gmail.com> wrote:
>
> small_image_url  Path.first(item, "SmallImage/URL").text
>       small_image_height  Path.first(item, "SmallImage/Height
> Units").text
>       small_image_width  Path.first(item, "SmallImage/Width
> Units").text
>       medium_image_url  Path.first(item, "MediumImage/URL").text
>       medium_image_height  Path.first(item, "MediumImage/Height
> Units").text
>       medium_image_width  Path.first(item, "MediumImage/Width
> Units").text
>       large_image_url  Path.first(item, "LargeImage/URL").text
>       large_image_height  Path.first(item, "LargeImage/Height
> Units").text
>       large_image_width  Path.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...


class Image
  attr_reader :height, :width, :url

  def initialize(item, image_name)
    @height  Path.first(item, image_name + "/Height Units").text
    @width  Path.first(item, image_name + "/Width Units").text
    @url  Path.first(item, image_name + "/URL").text
  end
end

small_image  mage.new(item, "SmallImage")
medium_image  mage.new(item, "MediumImage")
large_image  mage.new(item, "LargeImage")

Then you can access the url, height, and width via the appropriate method on
each Image instance.

puts "SmallImage URL: #{small_image.url}"
puts "SmallImage Height: #{small_image.height}"
puts "SmallImage Width: #{small_image.width}"

I'm sure others will have much nicer ways, but this was the first thing to
come to mind.

def image_attributes (item, image_name)
>    height  Path.first(item, image_name + "/Height Units").text
>    width  Path.first(item, image_name + "/Width Units").text
>    url  Path.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?
>
>
>
HTH,
Michael Guterl

------art_18124_676102.1160626974424--