Class: Audioscrobbler::SubmissionQueue::PlayedTrack

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

Overview

A track that’s been played.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(artist, title, length, start_time, album = "", mbid = "", track_num = nil) ⇒ PlayedTrack

constructor

Parameters:

  • artist

    artist name

  • title

    track name

  • length

    track length

  • start_time

    track start time, as UTC unix time

  • album (defaults to: "")

    album name

  • mbid (defaults to: "")

    MusicBrainz ID

  • track_num (defaults to: nil)

    track number on album



563
564
565
566
567
568
569
570
571
572
# File 'lib/audioscrobbler.rb', line 563

def initialize(artist, title, length, start_time, album="", mbid="",
               track_num=nil)
  @artist = artist.to_s
  @title = title.to_s
  @length = length.to_i
  @start_time = start_time.to_i
  @album = album ? album.to_s : ""
  @mbid = mbid ? mbid.to_s : ""
  @track_num = track_num ? track_num.to_s : ""
end

Instance Attribute Details

#albumObject (readonly)

Returns the value of attribute album.



573
574
575
# File 'lib/audioscrobbler.rb', line 573

def album
  @album
end

#artistObject (readonly)

Returns the value of attribute artist.



573
574
575
# File 'lib/audioscrobbler.rb', line 573

def artist
  @artist
end

#lengthObject (readonly)

Returns the value of attribute length.



573
574
575
# File 'lib/audioscrobbler.rb', line 573

def length
  @length
end

#mbidObject (readonly)

Returns the value of attribute mbid.



573
574
575
# File 'lib/audioscrobbler.rb', line 573

def mbid
  @mbid
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



573
574
575
# File 'lib/audioscrobbler.rb', line 573

def start_time
  @start_time
end

#titleObject (readonly)

Returns the value of attribute title.



573
574
575
# File 'lib/audioscrobbler.rb', line 573

def title
  @title
end

#track_numObject (readonly)

Returns the value of attribute track_num.



573
574
575
# File 'lib/audioscrobbler.rb', line 573

def track_num
  @track_num
end

Class Method Details

.deserialize(str) ⇒ Object

Undo the operation performed by serialize(), returning a new PlayedTrack object (class method).

Parameters:

  • str

    serialized PlayedTrack to deserialize (string)



592
593
594
595
# File 'lib/audioscrobbler.rb', line 592

def self.deserialize(str)
  PlayedTrack.new(*str.split("\t").collect {|x|
    x ? CGI.unescape(x) : "" })
end

Instance Method Details

#==(other) ⇒ Object



597
598
599
600
601
602
# File 'lib/audioscrobbler.rb', line 597

def ==(other)
  other.class == PlayedTrack and @artist == other.artist and
    @title == other.title and @length == other.length and
    @start_time == other.start_time and @album == other.album and
    @mbid == other.mbid and @track_num == other.track_num
end

#serializeObject

Convert this track’s information into a form suitable for writing to a text file. Returns a string.



580
581
582
583
584
# File 'lib/audioscrobbler.rb', line 580

def serialize
  parts = [@artist, @title, @length.to_s, @start_time.to_s,
           @album, @mbid, @track_num]
  parts.collect {|x| x ? CGI.escape(x) : "" }.join("\t")
end