Class: Lastfm::Util
- Inherits:
-
Object
- Object
- Lastfm::Util
- Defined in:
- lib/lastfm/util.rb
Class Method Summary collapse
- .build_options(args, mandatory, optional) ⇒ Object
- .build_options_from_array(values, mandatory, optional) ⇒ Object
- .build_options_from_hash(options, mandatory, optional) ⇒ Object
- .force_array(array_or_something) ⇒ Object
Class Method Details
.build_options(args, mandatory, optional) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/lastfm/util.rb', line 7 def self.(args, mandatory, optional) if args.first.is_a?(Hash) (args.first, mandatory, optional) else (args, mandatory, optional) end end |
.build_options_from_array(values, mandatory, optional) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lastfm/util.rb', line 27 def self.(values, mandatory, optional) = {} mandatory.each_with_index do |name, index| raise ArgumentError.new('%s is required' % name) unless values[index] [name] = values[index] end optional.each_with_index do |name, index| value = name[1] if value.kind_of?(Proc) value = value.call end [name[0]] = values[index + mandatory.size] || value end end |
.build_options_from_hash(options, mandatory, optional) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lastfm/util.rb', line 15 def self.(, mandatory, optional) mandatory.each do |name| raise ArgumentError.new("%s is required" % name) unless [name] end optional.each do |name, value| [name] ||= value.kind_of?(Proc) ? value.call : value end 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 |