Class: VkMusic::Playlist

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/vk_music/playlist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list, options = {}) ⇒ Playlist

Returns a new instance of Playlist.

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vk_music/playlist.rb', line 29

def initialize(list, options = {})
  # Arguments check
  raise ArgumentError, "array of audios must be provided", caller unless list.class == Array
  
  # Saving list
  @list = list.dup
  
  # Setting up attributes
  @id          = options[:id].to_s
  @owner_id    = options[:owner_id].to_s
  @access_hash = options[:access_hash].to_s
  @title       = options[:title].to_s
  @subtitle    = options[:subtitle].to_s
end

Instance Attribute Details

#access_hashObject (readonly)

Returns the value of attribute access_hash.



6
7
8
# File 'lib/vk_music/playlist.rb', line 6

def access_hash
  @access_hash
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/vk_music/playlist.rb', line 6

def id
  @id
end

#owner_idObject (readonly)

Returns the value of attribute owner_id.



6
7
8
# File 'lib/vk_music/playlist.rb', line 6

def owner_id
  @owner_id
end

#subtitleObject (readonly)

Returns the value of attribute subtitle.



6
7
8
# File 'lib/vk_music/playlist.rb', line 6

def subtitle
  @subtitle
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/vk_music/playlist.rb', line 6

def title
  @title
end

Instance Method Details

#[](index) ⇒ Object



21
22
23
# File 'lib/vk_music/playlist.rb', line 21

def [](index)
  @list[index]
end

#each(&block) ⇒ Object



17
18
19
# File 'lib/vk_music/playlist.rb', line 17

def each(&block)
  @list.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/vk_music/playlist.rb', line 25

def empty?
  @list.empty?
end

#lengthObject Also known as: size



8
9
10
# File 'lib/vk_music/playlist.rb', line 8

def length
  @list.length
end

#to_sObject



13
14
15
# File 'lib/vk_music/playlist.rb', line 13

def to_s
  "#{@subtitle} - #{@title} (#{self.length} аудиозаписей)"
end