Class: Lastfm::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/lastfm/util.rb

Class Method Summary collapse

Class Method Details

.build_options(args, mandatory, optional) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lastfm/util.rb', line 7

def self.build_options(args, mandatory, optional)
  options = {}

  mandatory.each_with_index do |name, index|
    raise ArgumentError.new('%s is required' % name) unless args[index]
    options[name] = args[index]
  end

  optional.each_with_index do |name, index|
    value = name[1]
    if value.kind_of?(Proc)
      value = value.call
    end
    options[name[0]] = args[index + mandatory.size] || value
  end

  options
end

.force_array(array_or_something) ⇒ Object



3
4
5
# File 'lib/lastfm/util.rb', line 3

def self.force_array(array_or_something)
  array_or_something.kind_of?(Array) ? array_or_something : [array_or_something]
end