Class: Xiami::Song

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(song_url = nil) ⇒ Song

Returns a new instance of Song.



13
14
15
16
17
18
19
# File 'lib/xiami/song.rb', line 13

def initialize(song_url = nil)
  if song_url
    @id = song_url.match(/song\/([0-9]+)/)[1] rescue song_url

    parse_info!
  end
end

Instance Attribute Details

#albumObject

Returns the value of attribute album.



9
10
11
# File 'lib/xiami/song.rb', line 9

def album
  @album
end

#artistObject

Returns the value of attribute artist.



9
10
11
# File 'lib/xiami/song.rb', line 9

def artist
  @artist
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#local_file_pathObject

Returns the value of attribute local_file_path.



11
12
13
# File 'lib/xiami/song.rb', line 11

def local_file_path
  @local_file_path
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#temporary_urlObject

Returns the value of attribute temporary_url.



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

def temporary_url
  @temporary_url
end

Instance Method Details

#==(another) ⇒ Object



21
22
23
24
25
# File 'lib/xiami/song.rb', line 21

def ==(another)
  return false if another.nil?

  self.id == another.id
end

#album_nameObject



35
36
37
# File 'lib/xiami/song.rb', line 35

def album_name
  album.name
end

#artist_nameObject



31
32
33
# File 'lib/xiami/song.rb', line 31

def artist_name
  artist.name
end

#parse_info!Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/xiami/song.rb', line 39

def parse_info!
  doc  = Nokogiri::XML(info_xml)

  @id = doc.at_css('track song_id').content
  @name = CGI.unescapeHTML(doc.at_css('track song_name').content)

  @album = Album.new.tap do |album|
    album.id = doc.at_css('track album_id').content
    album.name = CGI.unescapeHTML(doc.at_css('track album_name').content)
    album.cover_url = doc.at_css('track album_cover').content
  end

  @artist = Artist.new.tap do |artist|
    artist.id = doc.at_css('track artist_id').content
    artist.name = CGI.unescapeHTML(doc.at_css('track artist_name').content)
  end

  @temporary_url = sospa(doc.at_css('track location').content)
end

#titleObject



27
28
29
# File 'lib/xiami/song.rb', line 27

def title
  name
end