Class: Grooveshark::Song

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Song

Returns a new instance of Song.



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

def initialize(data=nil)
  unless 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
end

Instance Attribute Details

#albumObject (readonly)

Returns the value of attribute album.



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

def album
  @album
end

#album_idObject (readonly)

Returns the value of attribute album_id.



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

def album_id
  @album_id
end

#artistObject (readonly)

Returns the value of attribute artist.



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

def artist
  @artist
end

#artist_idObject (readonly)

Returns the value of attribute artist_id.



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

def artist_id
  @artist_id
end

#artworkObject (readonly)

Returns the value of attribute artwork.



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

def artwork
  @artwork
end

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/grooveshark/song.rb', line 3

def data
  @data
end

#durationObject (readonly)

Returns the value of attribute duration.



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

def duration
  @duration
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#playcountObject (readonly)

Returns the value of attribute playcount.



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

def playcount
  @playcount
end

#trackObject (readonly)

Returns the value of attribute track.



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

def track
  @track
end

#yearObject (readonly)

Returns the value of attribute year.



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

def year
  @year
end

Instance Method Details

#to_hashObject

Hash export for API usage



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

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

#to_sObject

Presentable format



26
27
28
# File 'lib/grooveshark/song.rb', line 26

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