Class: Spotify::Models::ExternalID

Inherits:
Object
  • Object
show all
Defined in:
lib/spotify/models/external_id.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ ExternalID

Sets the arguments to its variables.

Parameters:

  • args (Hash) (defaults to: {})

    the arguments that will be placed on each variable.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/spotify/models/external_id.rb', line 14

def initialize(args = {})
  args = Hash(args).with_indifferent_access

  hsh = {
    isrc: args[:isrc],
    ean:  args[:ean],
    upc:  args[:upc]
  }

  hsh = hsh.reject { |_, v| v.blank? }

  if hsh.present?
    # Generates the keys dynamically
    hsh.each do |k, v|
      key   = k
      value = v

      eval("@#{key} = value")
      class_eval { attr_reader key.to_sym }
    end
  end
end