Class: Savio::ButtonManager
- Inherits:
-
Object
- Object
- Savio::ButtonManager
- Defined in:
- lib/savio/ButtonManager.rb
Constant Summary collapse
[]
Instance Attribute Summary collapse
-
#buttons ⇒ Object
readonly
Returns the value of attribute buttons.
-
#selected ⇒ Object
readonly
Returns the value of attribute selected.
Class Method Summary collapse
Instance Method Summary collapse
- #addButton(button) ⇒ Object
- #deselect(button) ⇒ Object
-
#initialize(args = {}) ⇒ ButtonManager
constructor
A new instance of ButtonManager.
- #removeButton(button, overwrite = true) ⇒ Object
- #select(button) ⇒ Object
- #toggle(button) ⇒ Object
- #type=(type) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ ButtonManager
Returns a new instance of ButtonManager.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/savio/ButtonManager.rb', line 10 def initialize(args = {}) @@buttonManagers.push(self) @buttons = [] @selected = [] @type = args[:type] || 'radio' if @type != 'checkbox' && @type != 'radio' raise ArgumentError, 'ButtonManager type ' + @type.to_s + ' is invalid. Must be radio or checkbox' end end |
Instance Attribute Details
#buttons ⇒ Object (readonly)
Returns the value of attribute buttons.
3 4 5 |
# File 'lib/savio/ButtonManager.rb', line 3 def @buttons end |
#selected ⇒ Object (readonly)
Returns the value of attribute selected.
3 4 5 |
# File 'lib/savio/ButtonManager.rb', line 3 def selected @selected end |
Class Method Details
.buttonManagers ⇒ Object
6 7 8 |
# File 'lib/savio/ButtonManager.rb', line 6 def self. @@buttonManagers end |
Instance Method Details
#addButton(button) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/savio/ButtonManager.rb', line 32 def addButton() if .class.name != 'Savio::Button' raise ArgumentError, 'Given object ' + .to_s + ' is not a Button. Must be of type Button' end .deselect(false) @buttons.push() if . != self . = self end end |
#deselect(button) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/savio/ButtonManager.rb', line 91 def deselect() if @buttons.include?() if @type == 'checkbox' @selected.delete() .deselect(false) elsif @type == 'radio' @selected.delete() .deselect(false) end else raise ArgumentError, ('Could not find button ' + .to_s + ' in buttonManager') end end |
#removeButton(button, overwrite = true) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/savio/ButtonManager.rb', line 43 def removeButton(, overwrite = true) if @buttons.include?() @buttons.delete() if @selected.include?() @selected.delete() end if overwrite == true . = nil end else raise ArgumentError, ('Could not find button ' + .to_s + ' in buttonManager') end end |
#select(button) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/savio/ButtonManager.rb', line 73 def select() if @buttons.include?() if @type == 'checkbox' @selected.push() .select(false) elsif @type == 'radio' @buttons.each do |i| i.deselect(false) end @selected.clear @selected.push() .select(false) end else raise ArgumentError, ('Could not find button ' + .to_s + ' in buttonManager') end end |
#toggle(button) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/savio/ButtonManager.rb', line 57 def toggle() if @buttons.include?() if @type == 'checkbox' if .selected deselect() else select() end elsif @type == 'radio' select() end else raise ArgumentError, ('Could not find button ' + .to_s + ' in buttonManager') end end |
#type=(type) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/savio/ButtonManager.rb', line 24 def type=(type) if type == 'radio' || type == "checkbox" @type = type else raise ArgumentError, 'ButtonManager type ' + type.to_s + ' is invalid. Must be radio or checkbox' end end |