Class: Spot::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/spot/base.rb

Direct Known Subclasses

Album, Artist, Song

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Base

Returns a new instance of Base.



7
8
9
# File 'lib/spot/base.rb', line 7

def initialize(args)
  args.keys.each { |name| instance_variable_set "@" + name.to_s.gsub(/[^a-z]/i, ''), args[name] }
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/spot/base.rb', line 5

def name
  @name
end

Instance Method Details

#available?(territory = nil) ⇒ Boolean

Is the object available in territory? Where territory can be any string representation of the ISO 3166-1 alpha-2 table Read more about it here: en.wikipedia.org/wiki/ISO_3166-1_alpha-2 Sweden => SE Norway => NO

Returns:

  • (Boolean)


21
22
23
# File 'lib/spot/base.rb', line 21

def available?(territory = nil)
  territories.include?(territory)
end

#href(type = "spotify") ⇒ Object

Returns a URL for the object type can contain the value “spotify” or “href” href => open.spotify.com/track/5DhDGwNXRPHsMApbtVKvFb spotify => spotify:track:5DhDGwNXRPHsMApbtVKvFb



29
30
31
# File 'lib/spot/base.rb', line 29

def href(type = "spotify")
  send("href_#{type}")
end

#popularityObject

Returns a value from 0 to 1 The return type if float



40
41
42
# File 'lib/spot/base.rb', line 40

def popularity
  @_popularity ||= @popularity.to_f
end

#to_sObject

Returns a string representation of the item



34
35
36
# File 'lib/spot/base.rb', line 34

def to_s
  not_implemented
end

#valid?Boolean

Is the object it self valid?

Returns:

  • (Boolean)


12
13
14
# File 'lib/spot/base.rb', line 12

def valid?
  not_implemented
end