Class: KBL::Package

Inherits:
Object
  • Object
show all
Includes:
Serializable::Package
Defined in:
lib/kbl/package.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Serializable::Package

#to_kbl, #to_kbl_node

Constructor Details

#initialize(&block) ⇒ Package

Returns a new instance of Package.



7
8
9
10
11
12
13
# File 'lib/kbl/package.rb', line 7

def initialize(&block)
  @date = Time.now
  @playlists = []
  @kkbox_version = "04000016"

  block.call(self) if block_given?
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



5
6
7
# File 'lib/kbl/package.rb', line 5

def date
  @date
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/kbl/package.rb', line 5

def description
  @description
end

#kkbox_versionObject (readonly)

Returns the value of attribute kkbox_version.



5
6
7
# File 'lib/kbl/package.rb', line 5

def kkbox_version
  @kkbox_version
end

#playlistsObject (readonly)

Returns the value of attribute playlists.



5
6
7
# File 'lib/kbl/package.rb', line 5

def playlists
  @playlists
end

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/kbl/package.rb', line 5

def version
  @version
end

Instance Method Details

#add_playlist(&block) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/kbl/package.rb', line 15

def add_playlist(&block)
  playlist = Playlist.new
  playlist.id = @playlists.size + 1
  block.call(playlist)

  @playlists << playlist
end

#total_songsObject



23
24
25
# File 'lib/kbl/package.rb', line 23

def total_songs
  @playlists.map { |playlist| playlist.songs.size }.reduce(:+)
end