Class: WindowTerminal::Window

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

Overview

The main class which handles each individual terminal window.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(orientation, name) ⇒ Window

Initializes Window object.



366
367
368
369
370
371
372
373
# File 'lib/accu-window.rb', line 366

def initialize(orientation,name)
	raise "Orientation must be passed!" if not orientation.is_a? Orientation
	@orientation = orientation
	@name = name
	@objects = []
	add_object(WindowTerminal::ColoredText.new(WindowTerminal::Orientation.new,@name,0,:red))
	add_object(WindowTerminal::Line.new(1))
end

Instance Attribute Details

#objectsObject (readonly)

Returns the value of attribute objects.



363
364
365
# File 'lib/accu-window.rb', line 363

def objects
  @objects
end

#orientationObject (readonly)

Returns the value of attribute orientation.



363
364
365
# File 'lib/accu-window.rb', line 363

def orientation
  @orientation
end

Instance Method Details

#[](index) ⇒ Object

Allows for array-like indexing of the Window’s objects.



434
435
436
# File 'lib/accu-window.rb', line 434

def [](index)
	@objects[index]
end

#add_object(object) ⇒ Object

Adds a single object to the Window’s object list.



383
384
385
386
# File 'lib/accu-window.rb', line 383

def add_object(object)
	raise ArgumentError "Argument must be a renderable object." if (not (object.respond_to?(:render_line) or object.respond_to?(:render)))
	@objects << object
end

#add_objects(*items) ⇒ Object

Adds all passed arguments to the Window’s object list.



390
391
392
393
394
395
# File 'lib/accu-window.rb', line 390

def add_objects(*items)
	raise ArgumentError "Argument missing" if items.length == 0
	items.each { |item|
		add_object(item)
	}
end

#for_objectsObject

Yields the passed block with each object.



399
400
401
402
403
# File 'lib/accu-window.rb', line 399

def for_objects()
	@objects.each {|object|
		yield object
	}
end

#get_nameObject

Returns Window’s current name.



418
419
420
# File 'lib/accu-window.rb', line 418

def get_name()
	@name
end

#include_in_render(bool = true) ⇒ Object

Includes the Window in the WindowTerminal module screen_render.



424
425
426
427
428
429
430
# File 'lib/accu-window.rb', line 424

def include_in_render(bool=true)
	if bool and not WindowTerminal.get_windows().include? self then
		WindowTerminal.add_window self
	elsif not bool and WindowTerminal.get_windows().include? self then
		WindowTerminal.remove_window self
	end
end

#set_name(name) ⇒ Object

Sets the Window’s current name and changes the displayed name accordingly.



408
409
410
411
412
413
414
# File 'lib/accu-window.rb', line 408

def set_name(name)
	raise TypeError "Name must be an string!" if (not name.is_a? String)
	@name = name
	if @objects[0].respond_to? :set_text then
		@objects[0].set_text @name
	end
end

#to_sObject

Makes the to_s method return something a bit more meaningful.



377
378
379
# File 'lib/accu-window.rb', line 377

def to_s
	"<Window: @orientation = #{@orientation.to_s}, @name = #{@name} >"
end