Class: Radiodan::Playlist
- Inherits:
-
Object
- Object
- Radiodan::Playlist
- 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
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#position ⇒ Object
Returns the value of attribute position.
-
#repeat ⇒ Object
(also: #repeat?)
Returns the value of attribute repeat.
-
#seek ⇒ Object
Returns the value of attribute seek.
-
#state ⇒ Object
Returns the value of attribute state.
-
#tracks ⇒ Object
Returns the value of attribute tracks.
-
#volume ⇒ Object
Returns the value of attribute volume.
Instance Method Summary collapse
- #attributes ⇒ Object (also: #as_json)
- #current ⇒ Object
-
#initialize(options = {}) ⇒ Playlist
constructor
A new instance of Playlist.
- #random? ⇒ Boolean
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(={}) self.state = .fetch(:state, STATES.first) self.mode = .fetch(:mode, MODES.first) self.repeat = .fetch(:repeat, false) self.tracks = .fetch(:tracks, Array.new) self.position = .fetch(:position, 0) self.seek = .fetch(:seek, 0.0) self.volume = .fetch(:volume, 100) end |
Instance Attribute Details
#mode ⇒ Object
Returns the value of attribute mode.
31 32 33 |
# File 'lib/radiodan/playlist.rb', line 31 def mode @mode end |
#position ⇒ Object
Returns the value of attribute position.
31 32 33 |
# File 'lib/radiodan/playlist.rb', line 31 def position @position end |
#repeat ⇒ Object Also known as: repeat?
Returns the value of attribute repeat.
31 32 33 |
# File 'lib/radiodan/playlist.rb', line 31 def repeat @repeat end |
#seek ⇒ Object
Returns the value of attribute seek.
31 32 33 |
# File 'lib/radiodan/playlist.rb', line 31 def seek @seek end |
#state ⇒ Object
Returns the value of attribute state.
31 32 33 |
# File 'lib/radiodan/playlist.rb', line 31 def state @state end |
#tracks ⇒ Object
Returns the value of attribute tracks.
31 32 33 |
# File 'lib/radiodan/playlist.rb', line 31 def tracks @tracks end |
#volume ⇒ Object
Returns the value of attribute volume.
31 32 33 |
# File 'lib/radiodan/playlist.rb', line 31 def volume @volume end |
Instance Method Details
#attributes ⇒ Object 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 |
#current ⇒ Object
45 46 47 |
# File 'lib/radiodan/playlist.rb', line 45 def current tracks[position] end |
#random? ⇒ Boolean
49 50 51 |
# File 'lib/radiodan/playlist.rb', line 49 def random? self.mode == :random end |