Class: Radiodan::Playlist

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/radiodan/playlist.rb

Defined Under Namespace

Classes: ModeError, PositionError, SeekError, StateError, VolumeError

Constant Summary collapse

STATES =
[:play, :stop, :pause]
MODES =
[:sequential, :resume, :random]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Playlist

Returns a new instance of Playlist.



35
36
37
38
39
40
41
42
43
# File 'lib/radiodan/playlist.rb', line 35

def initialize(options={})
  self.state    = options.fetch(:state, STATES.first)
  self.mode     = options.fetch(:mode, MODES.first)
  self.repeat   = options.fetch(:repeat, false)
  self.tracks   = options.fetch(:tracks, Array.new)
  self.position = options.fetch(:position, 0)
  self.seek     = options.fetch(:seek, 0.0)
  self.volume   = options.fetch(:volume, 100)
end

Instance Attribute Details

#modeObject

Returns the value of attribute mode.



31
32
33
# File 'lib/radiodan/playlist.rb', line 31

def mode
  @mode
end

#positionObject

Returns the value of attribute position.



31
32
33
# File 'lib/radiodan/playlist.rb', line 31

def position
  @position
end

#repeatObject Also known as: repeat?

Returns the value of attribute repeat.



31
32
33
# File 'lib/radiodan/playlist.rb', line 31

def repeat
  @repeat
end

#seekObject

Returns the value of attribute seek.



31
32
33
# File 'lib/radiodan/playlist.rb', line 31

def seek
  @seek
end

#stateObject

Returns the value of attribute state.



31
32
33
# File 'lib/radiodan/playlist.rb', line 31

def state
  @state
end

#tracksObject

Returns the value of attribute tracks.



31
32
33
# File 'lib/radiodan/playlist.rb', line 31

def tracks
  @tracks
end

#volumeObject

Returns the value of attribute volume.



31
32
33
# File 'lib/radiodan/playlist.rb', line 31

def volume
  @volume
end

Instance Method Details

#attributesObject Also known as: as_json



122
123
124
125
126
127
128
129
130
# File 'lib/radiodan/playlist.rb', line 122

def attributes
  { :state    => state,
    :mode     => mode,
    :repeat   => repeat,
    :tracks   => begin tracks.collect(&:attributes) rescue []; end,
    :position => position,
    :seek     => seek,
    :volume   => volume }
end

#currentObject



45
46
47
# File 'lib/radiodan/playlist.rb', line 45

def current
  tracks[position]
end

#random?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/radiodan/playlist.rb', line 49

def random?
  self.mode == :random
end