Class: Warg::Playlist

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

Defined Under Namespace

Classes: Start

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlaylist

Returns a new instance of Playlist.



1387
1388
1389
# File 'lib/warg.rb', line 1387

def initialize
  @start = @insert_at = Start.new
end

Instance Attribute Details

#insert_atObject (readonly)

Returns the value of attribute insert_at.



1385
1386
1387
# File 'lib/warg.rb', line 1385

def insert_at
  @insert_at
end

Instance Method Details

#playObject



1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
# File 'lib/warg.rb', line 1391

def play
  playing = @insert_at = @start
  command = nil

  while playing.next
    playing = @insert_at = playing.next

    if command != playing.command
      command = playing.command

      Warg.console.puts Console::SGR(command.command_name.console).with(text_color: :blue, effect: :bold)
    end

    Warg.console.puts Console::SGR(" -> #{playing.banner}").with(text_color: :magenta)

    result = playing.run

    if result.failed?
      command.on_failure(result)
    end
  end
end

#queue(command_step) ⇒ Object



1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
# File 'lib/warg.rb', line 1414

def queue(command_step)
  if @insert_at.next
    command_step.next = @insert_at.next
  end

  command_step.previous = @insert_at
  @insert_at.next = command_step

  @insert_at = command_step
end