Class: Segue::Notifiers

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

Instance Method Summary collapse

Constructor Details

#initializeNotifiers

Returns a new instance of Notifiers.



11
12
13
14
# File 'lib/segue/notifiers.rb', line 11

def initialize
  @preferences = Segue::Preferences.new
  @history = Segue::Paths.history
end

Instance Method Details

#track_finished(track) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/segue/notifiers.rb', line 41

def track_finished(track)
  @preferences[:started] = nil

  return unless track

  scrobbler&.scrobble(track[:artist], track[:title], timestamp: track[:start_time].to_i)
end

#track_resumed(track, elapsed) ⇒ Object



20
21
22
23
24
25
# File 'lib/segue/notifiers.rb', line 20

def track_resumed(track, elapsed)
  return unless track

  track[:start_time] = Time.now - elapsed
  @preferences[:started] = track[:start_time].to_i
end

#track_started(track) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/segue/notifiers.rb', line 27

def track_started(track)
  return unless track

  track[:start_time] = Time.now
  @preferences[:started] = track[:start_time].to_i
  scrobbler&.now_playing(track[:artist], track[:title])
  terminal_notify(
    message: "#{track[:title]} by #{track[:artist]}",
    title: "Now Playing"
  )

  File.open(@history, "a") { |file| file.puts history_line(track) }
end

#track_suspendedObject



16
17
18
# File 'lib/segue/notifiers.rb', line 16

def track_suspended
  @preferences[:started] = nil
end