Class: Biryani::Window

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_window_size) ⇒ Window

Returns a new instance of Window.

Parameters:

  • initial_window_size (Integer)


6
7
8
9
# File 'lib/biryani/window.rb', line 6

def initialize(initial_window_size)
  @length = initial_window_size
  @capacity = initial_window_size
end

Instance Attribute Details

#capacityObject (readonly)

Returns the value of attribute capacity.



3
4
5
# File 'lib/biryani/window.rb', line 3

def capacity
  @capacity
end

#lengthObject (readonly)

Returns the value of attribute length.



3
4
5
# File 'lib/biryani/window.rb', line 3

def length
  @length
end

Instance Method Details

#consume!(length) ⇒ Integer

Parameters:

  • length (Integer)

Returns:

  • (Integer)


14
15
16
# File 'lib/biryani/window.rb', line 14

def consume!(length)
  @length -= length
end

#increase!(length) ⇒ Integer

Parameters:

  • length (Integer)

Returns:

  • (Integer)


21
22
23
# File 'lib/biryani/window.rb', line 21

def increase!(length)
  @length += length
end

#update!(initial_window_size) ⇒ Integer

Parameters:

  • initial_window_size (Integer)

Returns:

  • (Integer)


28
29
30
31
32
# File 'lib/biryani/window.rb', line 28

def update!(initial_window_size)
  @length = initial_window_size - @capacity + @length
  @capacity = initial_window_size
  @length
end