Class: Xiami::Song
- Inherits:
-
Object
- Object
- Xiami::Song
- Defined in:
- lib/xiami/song.rb
Instance Attribute Summary collapse
-
#album ⇒ Object
Returns the value of attribute album.
-
#artist ⇒ Object
Returns the value of attribute artist.
-
#id ⇒ Object
Returns the value of attribute id.
-
#local_file_path ⇒ Object
Returns the value of attribute local_file_path.
-
#name ⇒ Object
Returns the value of attribute name.
-
#temporary_url ⇒ Object
Returns the value of attribute temporary_url.
Instance Method Summary collapse
- #==(another) ⇒ Object
- #album_name ⇒ Object
- #artist_name ⇒ Object
-
#initialize(song_url = nil) ⇒ Song
constructor
A new instance of Song.
- #parse_info! ⇒ Object
- #title ⇒ Object
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
#album ⇒ Object
Returns the value of attribute album.
9 10 11 |
# File 'lib/xiami/song.rb', line 9 def album @album end |
#artist ⇒ Object
Returns the value of attribute artist.
9 10 11 |
# File 'lib/xiami/song.rb', line 9 def artist @artist end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/xiami/song.rb', line 8 def id @id end |
#local_file_path ⇒ Object
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 |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/xiami/song.rb', line 8 def name @name end |
#temporary_url ⇒ Object
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_name ⇒ Object
35 36 37 |
# File 'lib/xiami/song.rb', line 35 def album_name album.name end |
#artist_name ⇒ Object
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 |
#title ⇒ Object
27 28 29 |
# File 'lib/xiami/song.rb', line 27 def title name end |