Class: Segue::Preferences

Inherits:
Object
  • Object
show all
Defined in:
lib/segue/preferences.rb

Instance Method Summary collapse

Constructor Details

#initializePreferences

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

Returns:

  • (Boolean)


13
14
15
# File 'lib/segue/preferences.rb', line 13

def continue?
  self[:autoplay]
end

#crossfade?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/segue/preferences.rb', line 17

def crossfade?
  self[:autoplay] && self[:crossfade]
end

#pause?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


33
34
35
# File 'lib/segue/preferences.rb', line 33

def play?
  reset(:play)
end

#scrobble?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/segue/preferences.rb', line 21

def scrobble?
  self[:scrobble]
end

#skip?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/segue/preferences.rb', line 37

def skip?
  reset(:skip)
end

#stop?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/segue/preferences.rb', line 29

def stop?
  reset(:stop)
end