Class: Idiomag::Recommendation

Inherits:
Object
  • Object
show all
Defined in:
lib/idiomag/recommendation.rb

Constant Summary collapse

ValidNetworks =
[:lastfm,:mog,:ilike,:mystrands,:projectplaylist,:imeem,:pandora,:bebo,:myspace,:songza]

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Recommendation

Returns a new instance of Recommendation.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/idiomag/recommendation.rb', line 5

def initialize(options)
  if !options[:network].blank? && !options[:user].blank?
    @user = options[:user]
    @network = options[:network]
    raise ArgumentError if !ValidNetworks.include?(@network)
    @query = {:network => @network,:username => @user}
  elsif !options[:apml].blank?
    @apml = options[:apml]
    @query = {:apml => @apml}
  elsif !options[:artists].blank? && options[:artists].is_a?(Array)
    @artist_list = options[:artists]
    @query = {:artists => @artist_list}
  else
    raise ArgumentError
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/idiomag/recommendation.rb', line 44

def method_missing(method, *args)  
  case method
  when :articles
    get_articles if @articles.nil?
    @articles
  when :artists
    get_artists if @artists.nil?
    @artists
  else
    super
  end
end

Instance Method Details

#get(*args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/idiomag/recommendation.rb', line 22

def get(*args)
  args.each do |action|
    case action
    when :articles
      get_articles
    when :artists
      get_artists
    else
      raise ArgumentError
    end
  end
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
# File 'lib/idiomag/recommendation.rb', line 35

def respond_to?(method)
  case method
  when :articles,:artists
    true
  else
    super
  end
end