Module: Scrobbler::ImageObjectFuncs

Included in:
Event, Playlist, Track, User
Defined in:
lib/scrobbler/helper/image.rb

Overview

Defines some functions that are used nearly all Scrobbler classes which have to deal with image references.

This module defines the object functions, use “include ImageObjectFuncs” in class.

Instance Method Summary collapse

Instance Method Details

#check_image_node(node) ⇒ Object

Check if the given libxml node is an image referencing node and in case of, read it into the object



28
29
30
31
32
33
34
35
# File 'lib/scrobbler/helper/image.rb', line 28

def check_image_node(node)
  if node.name == 'image'
    @image_small = node.content if node['size'] == 'small'
    @image_medium = node.content if node['size'] == 'medium'
    @image_large = node.content if node['size'] == 'large'
    @image_extralarge = node.content if node['size'] == 'extralarge'
  end
end

#image(which = :small) ⇒ Object

Return the URL to the specified image size.

If the URL to the given image size is not known and a ‘load_info’-function is defined, it will be called.

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
49
50
# File 'lib/scrobbler/helper/image.rb', line 41

def image(which=:small)
  which = which.to_s
  raise ArgumentError unless ['small', 'medium', 'large', 'extralarge'].include?(which)      
  img_url = instance_variable_get("@image_#{which}")
  if img_url.nil? && responds_to?(:load_info) 
    load_info 
    img_url = instance_variable_get("@image_#{which}")
  end
  img_url
end