Sha256: 6795cea45e88d3dbb204af5c1ffa24c678e205b4bda030c3e7af9dd02e5c3062

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

require "abstract"

module Spot
  class Base
    attr_reader :name
    
    def initialize(args)
      args.keys.each { |name| instance_variable_set "@" + name.to_s.gsub(/[^a-z]/i, ''), args[name] }
    end
    
    # Is the object it self valid?
    def valid?
      not_implemented
    end
    
    # 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: http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
    # Sweden => SE
    # Norway => NO
    def available?(territory = nil)
      territories.include?(territory)
    end
    
    # Returns a URL for the object
    # {type} can contain the value "spotify" or "href"
    # href => http://open.spotify.com/track/5DhDGwNXRPHsMApbtVKvFb
    # spotify => spotify:track:5DhDGwNXRPHsMApbtVKvFb
    def href(type = "spotify")
      send("href_#{type}")
    end
    
    # Returns a string representation of the item
    def to_s
      not_implemented
    end
    
    # Returns a value from 0 to 1
    # The return type if float
    def popularity
      @_popularity ||= @popularity.to_f
    end
    
    protected
      def territories
        not_implemented
      end
      
    private
      def href_http
        "http://open.spotify.com/#{$1}/#{$2}" if href_spotify.to_s =~ /spotify:(\w+):(\w+)/
      end
      
      def href_spotify
        @href
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spot-2.0.4 lib/spot/base.rb
spot-2.0.1 lib/spot/base.rb
spot-2.0.0 lib/spot/base.rb