Class: Grooveshark::Song

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

Overview

Song class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Song

Returns a new instance of Song.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/grooveshark/song.rb', line 10

def initialize(data = nil)
  return if data.nil?

  @data       = data
  @id         = data['song_id']
  @name       = data['song_name'] || data['name']
  @artist     = data['artist_name']
  @artist_id  = data['artist_id']
  @album      = data['album_name']
  @album_id   = data['album_id']
  @track      = data['track_num']
  @duration   = data['estimate_duration']
  @artwork    = data['cover_art_filename']
  @playcount  = data['song_plays']
  @year       = data['year']
end

Instance Attribute Details

#albumObject (readonly)

Returns the value of attribute album.



7
8
9
# File 'lib/grooveshark/song.rb', line 7

def album
  @album
end

#album_idObject (readonly)

Returns the value of attribute album_id.



6
7
8
# File 'lib/grooveshark/song.rb', line 6

def album_id
  @album_id
end

#artistObject (readonly)

Returns the value of attribute artist.



7
8
9
# File 'lib/grooveshark/song.rb', line 7

def artist
  @artist
end

#artist_idObject (readonly)

Returns the value of attribute artist_id.



6
7
8
# File 'lib/grooveshark/song.rb', line 6

def artist_id
  @artist_id
end

#artworkObject (readonly)

Returns the value of attribute artwork.



8
9
10
# File 'lib/grooveshark/song.rb', line 8

def artwork
  @artwork
end

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/grooveshark/song.rb', line 5

def data
  @data
end

#durationObject (readonly)

Returns the value of attribute duration.



8
9
10
# File 'lib/grooveshark/song.rb', line 8

def duration
  @duration
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/grooveshark/song.rb', line 6

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/grooveshark/song.rb', line 7

def name
  @name
end

#playcountObject (readonly)

Returns the value of attribute playcount.



8
9
10
# File 'lib/grooveshark/song.rb', line 8

def playcount
  @playcount
end

#trackObject (readonly)

Returns the value of attribute track.



7
8
9
# File 'lib/grooveshark/song.rb', line 7

def track
  @track
end

#yearObject (readonly)

Returns the value of attribute year.



7
8
9
# File 'lib/grooveshark/song.rb', line 7

def year
  @year
end

Instance Method Details

#to_hashObject

Hash export for API usage



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/grooveshark/song.rb', line 33

def to_hash
  {
    'songID'      => @id,
    'songName'    => @name,
    'artistName'  => @artist,
    'artistID'    => @artist_id,
    'albumName'   => @album,
    'albumID'     => @album_id,
    'track'       => @track
  }
end

#to_sObject

Presentable format



28
29
30
# File 'lib/grooveshark/song.rb', line 28

def to_s
  [@id, @name, @artist].join(' - ')
end