Class: MikePlayer::Display

Inherits:
Object
  • Object
show all
Defined in:
lib/mikeplayer/display.rb

Constant Summary collapse

PAUSE_INDICATOR =
'||'.freeze
INDICATOR_SIZE =
4

Instance Method Summary collapse

Constructor Details

#initializeDisplay

Returns a new instance of Display.



6
7
8
9
10
# File 'lib/mikeplayer/display.rb', line 6

def initialize
  @width     = 0
  @indicator = ''
  @changed   = false
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/mikeplayer/display.rb', line 45

def changed?
  true == @changed
end

#display!(elapsed_info, countdown = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mikeplayer/display.rb', line 28

def display!(elapsed_info, countdown = nil)
  return unless changed?

  mindicator = "(#{countdown}↓) " if countdown

  print("\r" << ' '.ljust(@width))

  info  = "#{@info_prefix} #{elapsed_info} #{mindicator}#{@indicator}"

  print(info)

  @width   = info.size
  @changed = false

  $stdout.flush
end

#elapsed=(v) ⇒ Object



16
17
18
19
# File 'lib/mikeplayer/display.rb', line 16

def elapsed=(v)
  @indicator = "#{'>' * (v % INDICATOR_SIZE)}".ljust(INDICATOR_SIZE)
  @changed   = true
end

#pausedObject



21
22
23
24
25
26
# File 'lib/mikeplayer/display.rb', line 21

def paused
  if (false == @indicator.include?(PAUSE_INDICATOR))
    @indicator = PAUSE_INDICATOR.ljust(INDICATOR_SIZE)
    @changed   = true
  end
end

#song_info=(v) ⇒ Object



12
13
14
# File 'lib/mikeplayer/display.rb', line 12

def song_info=(v)
  @info_prefix = "\r#{v}".freeze
end