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.



1476
1477
1478
# File 'lib/warg.rb', line 1476

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

Instance Attribute Details

#insert_atObject (readonly)

Returns the value of attribute insert_at.



1474
1475
1476
# File 'lib/warg.rb', line 1474

def insert_at
  @insert_at
end

Instance Method Details

#playObject



1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
# File 'lib/warg.rb', line 1480

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



1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
# File 'lib/warg.rb', line 1503

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