Module: Scrobbler::ImageObjectFuncs
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)
-
- (Object) check_image_node(node)
Check if the given libxml node is an image referencing node and in case of, read it into the object.
-
- (Object) image(which = :small)
Return the URL to the specified image size.
Instance Method Details
- (Object) check_image_node(node)
Check if the given libxml node is an image referencing node and in case of, read it into the object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/scrobbler/helper/image.rb', line 41 def check_image_node(node) if node.name == 'image' case node['size'].to_s # convert to string to fix libxml-ruby bug when 'small' @image_small = node.content when 'medium' @image_medium = node.content when 'large' @image_large = node.content when 'extralarge' @image_extralarge = node.content when 'mega' @image_mega = node.content else raise NotImplementedError, "Image size '#{node['size'].to_s}' not supported." end #^ case end end |
- (Object) image(which = :small)
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.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/scrobbler/helper/image.rb', line 64 def image(which=:small) which = which.to_s raise ArgumentError unless ['small', 'medium', 'large', 'extralarge', 'mega'].include?(which) img_url = instance_variable_get("@image_#{which}") if img_url.nil? && respond_to?(:load_info) load_info img_url = instance_variable_get("@image_#{which}") end img_url end |