Class: VkMusic::Playlist
- Inherits:
-
Object
- Object
- VkMusic::Playlist
- Includes:
- Enumerable
- Defined in:
- lib/vk_music/playlist.rb
Overview
VK playlist.
Instance Attribute Summary collapse
-
#access_hash ⇒ String?
readonly
Access hash which should be part of link for some playlists.
-
#id ⇒ Integer?
readonly
Playlist ID.
-
#owner_id ⇒ Integer?
readonly
Owner of playlist ID.
-
#real_size ⇒ Integer?
readonly
Real size of playlist or
nil
if unknown. -
#subtitle ⇒ String?
readonly
Playlist subtitle.
-
#title ⇒ String
readonly
Playlist title.
Instance Method Summary collapse
-
#[](index) ⇒ Audio?
Access audios from playlist.
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(list, options = {}) ⇒ Playlist
constructor
Initialize new playlist.
- #length ⇒ Object (also: #size)
-
#pp ⇒ String
Same to #to_s, but also outputs list of audios.
-
#to_a ⇒ Array<Audio>
Returns duplicate of array of playlist audios.
-
#to_s ⇒ String
Playlist description in Russian.
Constructor Details
#initialize(list, options = {}) ⇒ Playlist
Initialize new playlist.
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/vk_music/playlist.rb', line 92 def initialize(list, = {}) raise ArgumentError, "Bad arguments", caller unless list.class == Array # Saving list @list = list.dup # Setting up attributes @id = Utility.unless_nil_to Integer, [:id] @owner_id = Utility.unless_nil_to Integer, [:owner_id] @access_hash = Utility.unless_nil_to String, [:access_hash] @title = [:title].to_s @subtitle = Utility.unless_nil_to String, [:subtitle] @real_size = Utility.unless_nil_to Integer, [:real_size] end |
Instance Attribute Details
#access_hash ⇒ String? (readonly)
Returns access hash which should be part of link for some playlists.
18 19 20 |
# File 'lib/vk_music/playlist.rb', line 18 def access_hash @access_hash end |
#id ⇒ Integer? (readonly)
Returns playlist ID.
10 11 12 |
# File 'lib/vk_music/playlist.rb', line 10 def id @id end |
#owner_id ⇒ Integer? (readonly)
Returns owner of playlist ID.
14 15 16 |
# File 'lib/vk_music/playlist.rb', line 14 def owner_id @owner_id end |
#real_size ⇒ Integer? (readonly)
Returns real size of playlist or nil
if unknown.
30 31 32 |
# File 'lib/vk_music/playlist.rb', line 30 def real_size @real_size end |
#subtitle ⇒ String? (readonly)
Returns playlist subtitle. May be empty.
26 27 28 |
# File 'lib/vk_music/playlist.rb', line 26 def subtitle @subtitle end |
#title ⇒ String (readonly)
Returns playlist title.
22 23 24 |
# File 'lib/vk_music/playlist.rb', line 22 def title @title end |
Instance Method Details
#[](index) ⇒ Audio?
Access audios from playlist.
77 78 79 |
# File 'lib/vk_music/playlist.rb', line 77 def [](index) @list[index] end |
#each(&block) ⇒ Object
54 55 56 |
# File 'lib/vk_music/playlist.rb', line 54 def each(&block) @list.each(&block) end |
#empty? ⇒ Boolean
67 68 69 |
# File 'lib/vk_music/playlist.rb', line 67 def empty? @list.empty? end |
#length ⇒ Object Also known as: size
60 61 62 |
# File 'lib/vk_music/playlist.rb', line 60 def length @list.length end |
#pp ⇒ String
Returns Same to #to_s, but also outputs list of audios.
42 43 44 |
# File 'lib/vk_music/playlist.rb', line 42 def pp "#{to_s}:\n#{@list.map(&:pp).join("\n")}" end |
#to_a ⇒ Array<Audio>
Returns duplicate of array of playlist audios.
48 49 50 |
# File 'lib/vk_music/playlist.rb', line 48 def to_a @list.dup end |
#to_s ⇒ String
Returns playlist description in Russian.
34 35 36 37 38 |
# File 'lib/vk_music/playlist.rb', line 34 def to_s (@subtitle && !@subtitle.empty? ? "#{@subtitle} - " : "") + @title + (@real_size ? "(#{self.length} из #{@real_size} аудиозаписей загружено)" : " (#{self.length} аудиозаписей)") end |