Module: Cura::Attributes::HasWindows

Included in:
Cura::Application
Defined in:
lib/cura/attributes/has_windows.rb

Overview

Allows an object to have windows. TODO: Lots of code is the same as HasChildren

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#windowsObject (readonly)

Get the windows of this object.



19
20
21
# File 'lib/cura/attributes/has_windows.rb', line 19

def windows
  @windows
end

Instance Method Details

#add_window(window) ⇒ Window

Add a window to this object.

Parameters:

Returns:

Raises:

  • (TypeError)


25
26
27
28
29
30
31
# File 'lib/cura/attributes/has_windows.rb', line 25

def add_window(window)
  raise TypeError, "window must be a Cura::Window" unless window.is_a?(Window)
  
  @windows << window
  
  window
end

#delete_window(window) ⇒ Window

Remove a window from this object’s windows.

Parameters:

Returns:

Raises:

  • (TypeError)


45
46
47
48
49
50
# File 'lib/cura/attributes/has_windows.rb', line 45

def delete_window(window)
  raise TypeError, "window must be a Cura::Window" unless window.is_a?(Window)
  index = @windows.index(window)
  
  delete_window_at(index)
end

#delete_window_at(index) ⇒ Window

Remove a window from this object’s windows at the given index.

Parameters:

  • index (#to_i)

Returns:



37
38
39
# File 'lib/cura/attributes/has_windows.rb', line 37

def delete_window_at(index)
  @windows.delete_at(index.to_i)
end

#delete_windowsObject

Remove all windows.



53
54
55
# File 'lib/cura/attributes/has_windows.rb', line 53

def delete_windows
  (0...@windows.count).to_a.each { |index| delete_window_at(index) }
end

#initialize(*arguments) ⇒ Object



12
13
14
15
16
# File 'lib/cura/attributes/has_windows.rb', line 12

def initialize(*arguments)
  @windows = []
  
  super
end