Class: Vedeu::Models::Group
- Inherits:
-
Object
- Object
- Vedeu::Models::Group
- Includes:
- Vedeu::Model, Toggleable
- Defined in:
- lib/vedeu/models/group.rb,
lib/vedeu/models/groups.rb
Overview
Groups
Instance Attribute Summary collapse
Attributes included from Toggleable
Attributes included from Vedeu::Model
Instance Method Summary collapse
-
#add(member) ⇒ Vedeu::Models::Group
Add a member to the group by name.
-
#attributes ⇒ Hash<Symbol => void>
Returns the attributes of the group.
-
#by_zindex ⇒ Array<String>
Return the members of the group sorted by the zindex of the members.
-
#defaults ⇒ Hash
private
Returns the default options/attributes for this class.
-
#hide ⇒ Vedeu::Models::Group
Hide the named group of interfaces, or without a name, the group of the currently focussed interface.
-
#initialize(attributes = {}) ⇒ Vedeu::Models::Group
constructor
Return a new instance of Vedeu::Models::Group.
-
#interfaces ⇒ Array<Vedeu::Models::Interface]
private
Return the interfaces for all members of the group.
-
#members ⇒ Set
Return the members of the group.
-
#remove(member) ⇒ Vedeu::Models::Group
Remove a member from the group by name.
-
#reset ⇒ Vedeu::Models::Group
Remove all members from the group.
-
#show ⇒ Vedeu::Models::Group
Show the named group of interfaces, or without a name, the group of the currently focussed interface.
-
#toggle ⇒ Vedeu::Models::Group
Toggle the visibility of the group with the given name.
Methods included from Toggleable
Methods included from Vedeu::Model
#deputy, #dsl_class, included, #store
Methods included from Common
#demodulize, #present?, #snake_case
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Models::Group
A group being visible or not may not necessarily mean the members are of the same state.
Return a new instance of Vedeu::Models::Group.
32 33 34 35 36 37 38 |
# File 'lib/vedeu/models/group.rb', line 32 def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @attributes.each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#name ⇒ String
15 16 17 |
# File 'lib/vedeu/models/group.rb', line 15 def name @name end |
Instance Method Details
#add(member) ⇒ Vedeu::Models::Group
Add a member to the group by name.
44 45 46 47 48 |
# File 'lib/vedeu/models/group.rb', line 44 def add(member) attrs = attributes.merge!(members: members.add(member)) Vedeu::Models::Group.new(attrs).store end |
#attributes ⇒ Hash<Symbol => void>
Returns the attributes of the group.
53 54 55 56 57 58 59 60 |
# File 'lib/vedeu/models/group.rb', line 53 def attributes { name: name, members: members, repository: repository, visible: visible, } end |
#by_zindex ⇒ Array<String>
Return the members of the group sorted by the zindex of the members.
66 67 68 |
# File 'lib/vedeu/models/group.rb', line 66 def by_zindex interfaces.sort { |a, b| a.zindex <=> b.zindex }.map(&:name) end |
#defaults ⇒ Hash (private)
Returns the default options/attributes for this class.
155 156 157 158 159 160 161 162 |
# File 'lib/vedeu/models/group.rb', line 155 def defaults { members: Set.new, name: '', repository: Vedeu.groups, visible: true, } end |
#hide ⇒ Vedeu::Models::Group
The action of showing a group will effectively clear the terminal and show the new group, therefore hiding the group may not be necessary.
Hide the named group of interfaces, or without a name, the group of the currently focussed interface. Useful for hiding part of that which is currently displaying in the terminal.
83 84 85 86 87 88 89 90 91 |
# File 'lib/vedeu/models/group.rb', line 83 def hide super @members.each do |member| Vedeu::Models::Interface.hide_interface(member) end self end |
#interfaces ⇒ Array<Vedeu::Models::Interface] (private)
Return the interfaces for all members of the group.
167 168 169 |
# File 'lib/vedeu/models/group.rb', line 167 def interfaces members.map { |name| Vedeu.interfaces.by_name(name) } end |
#members ⇒ Set
Return the members of the group.
96 97 98 |
# File 'lib/vedeu/models/group.rb', line 96 def members @_members ||= Set.new(@members) end |
#remove(member) ⇒ Vedeu::Models::Group
Remove a member from the group by name.
104 105 106 107 108 |
# File 'lib/vedeu/models/group.rb', line 104 def remove(member) attrs = attributes.merge!(members: members.delete(member)) Vedeu::Models::Group.new(attrs).store end |
#reset ⇒ Vedeu::Models::Group
Remove all members from the group.
113 114 115 116 117 |
# File 'lib/vedeu/models/group.rb', line 113 def reset attrs = defaults.merge!(name: name) Vedeu::Models::Group.new(attrs).store end |
#show ⇒ Vedeu::Models::Group
Show the named group of interfaces, or without a name, the group of the currently focussed interface.
127 128 129 130 131 132 133 134 135 |
# File 'lib/vedeu/models/group.rb', line 127 def show super @members.each do |member| Vedeu::Models::Interface.show_interface(member) end self end |
#toggle ⇒ Vedeu::Models::Group
Toggle the visibility of the group with the given name.
144 145 146 147 148 |
# File 'lib/vedeu/models/group.rb', line 144 def toggle super self end |