Sha256: 48f5e5f538395d1a337b61a9dbb4902a2de82df0cd241a8fc9b0a9a0555babe7

Contents?: true

Size: 744 Bytes

Versions: 3

Compression:

Stored size: 744 Bytes

Contents

require 'forwardable'
require 'active_support/core_ext/hash/indifferent_access'

class Radiodan
class Track
  class NoFileError < Exception; end
  extend  Forwardable
  def_delegators :@attributes, :[]
  
  alias_method :eql?, :==
  
  def initialize(attributes={})
    @attributes = HashWithIndifferentAccess.new(attributes)
    raise NoFileError, 'No file given for track' \
      unless @attributes.include?(:file)
  end
  
  def ==(other)
    self[:file] == other[:file]
  end
  
  def method_missing(method, *args, &block)
    if @attributes.include?(method)
      @attributes[method]
    else
      super
    end
  end
  
  def respond_to?(method)
    if @attributes.include?(method)
      true
    else
      super
    end
  end
end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
radiodan-0.0.4 lib/radiodan/track.rb
radiodan-0.0.3 lib/radiodan/track.rb
radiodan-0.0.2 lib/radiodan/track.rb