Class: Segue::Preferences
- Inherits:
-
Object
- Object
- Segue::Preferences
- Defined in:
- lib/segue/preferences.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #continue? ⇒ Boolean
- #crossfade? ⇒ Boolean
-
#initialize ⇒ Preferences
constructor
A new instance of Preferences.
- #pause? ⇒ Boolean
- #persist(preferences) ⇒ Object
- #play? ⇒ Boolean
- #scrobble? ⇒ Boolean
- #skip? ⇒ Boolean
- #stop? ⇒ Boolean
Constructor Details
#initialize ⇒ Preferences
Returns a new instance of Preferences.
8 9 10 11 |
# File 'lib/segue/preferences.rb', line 8 def initialize @path = Segue::Paths.preferences persist({ autoplay: true, crossfade: true }) unless File.exist?(@path) end |
Instance Method Details
#[](key) ⇒ Object
41 42 43 |
# File 'lib/segue/preferences.rb', line 41 def [](key) load_preferences[key] end |
#[]=(key, value) ⇒ Object
45 46 47 48 49 |
# File 'lib/segue/preferences.rb', line 45 def []=(key, value) preferences = load_preferences preferences[key] = value persist(preferences) end |
#continue? ⇒ Boolean
13 14 15 |
# File 'lib/segue/preferences.rb', line 13 def continue? self[:autoplay] end |
#crossfade? ⇒ Boolean
17 18 19 |
# File 'lib/segue/preferences.rb', line 17 def crossfade? self[:autoplay] && self[:crossfade] end |
#pause? ⇒ Boolean
25 26 27 |
# File 'lib/segue/preferences.rb', line 25 def pause? reset(:pause) end |
#persist(preferences) ⇒ Object
51 52 53 |
# File 'lib/segue/preferences.rb', line 51 def persist(preferences) File.open(@path, "w") { |f| f.puts preferences.to_yaml } end |
#play? ⇒ Boolean
33 34 35 |
# File 'lib/segue/preferences.rb', line 33 def play? reset(:play) end |
#scrobble? ⇒ Boolean
21 22 23 |
# File 'lib/segue/preferences.rb', line 21 def scrobble? self[:scrobble] end |
#skip? ⇒ Boolean
37 38 39 |
# File 'lib/segue/preferences.rb', line 37 def skip? reset(:skip) end |
#stop? ⇒ Boolean
29 30 31 |
# File 'lib/segue/preferences.rb', line 29 def stop? reset(:stop) end |