Class: BBC::Music::Song
- Inherits:
-
Object
- Object
- BBC::Music::Song
- Defined in:
- lib/bbc/music/song.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#artist_gid ⇒ Object
readonly
Returns the value of attribute artist_gid.
-
#artist_name ⇒ Object
readonly
Returns the value of attribute artist_name.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #artist ⇒ Object
-
#initialize(params) ⇒ Song
constructor
A new instance of Song.
- #to_h ⇒ Object
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(params) ⇒ Song
Returns a new instance of Song.
17 18 19 20 21 22 23 24 25 |
# File 'lib/bbc/music/song.rb', line 17 def initialize(params) if params @artist_gid = params['artist_gid'] @artist_name = params['artist'] @title = params['title'] else raise BBC::NoDataReturnedError end end |
Instance Attribute Details
#artist_gid ⇒ Object (readonly)
Returns the value of attribute artist_gid.
7 8 9 |
# File 'lib/bbc/music/song.rb', line 7 def artist_gid @artist_gid end |
#artist_name ⇒ Object (readonly)
Returns the value of attribute artist_name.
7 8 9 |
# File 'lib/bbc/music/song.rb', line 7 def artist_name @artist_name end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/bbc/music/song.rb', line 7 def title @title end |
Class Method Details
.played_recently ⇒ Object
13 14 15 |
# File 'lib/bbc/music/song.rb', line 13 def self.played_recently Array.wrap(CLIENT..slice(1, 6)).map { |song| new(song) } end |
.playing_now ⇒ Object
9 10 11 |
# File 'lib/bbc/music/song.rb', line 9 def self. new(CLIENT..first) end |
Instance Method Details
#artist ⇒ Object
27 28 29 |
# File 'lib/bbc/music/song.rb', line 27 def artist @artist ||= BBC::Music::Artist.find(artist_gid) end |
#to_h ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/bbc/music/song.rb', line 31 def to_h { :artist_gid => @artist_gid, :artist_name => @artist_name, :title => @title } end |
#to_json(options = {}) ⇒ Object
39 40 41 |
# File 'lib/bbc/music/song.rb', line 39 def to_json(={}) JSON.generate(to_h) end |