lib/vedeu/groups/group.rb in vedeu-0.6.20 vs lib/vedeu/groups/group.rb in vedeu-0.6.21
- old
+ new
@@ -12,20 +12,26 @@
# @!attribute [rw] name
# @return [String]
attr_accessor :name
+ # @param (see #initialize)
+ # @return (see #initialize)
+ def self.store(attributes = {})
+ new(attributes).store
+ end
+
# Return a new instance of Vedeu::Groups::Group.
#
# @note
# A group being visible or not may not necessarily mean the
# members are of the same state.
#
# @param attributes [Hash]
# @option attributes members [Set] A collection of names of
# interfaces belonging to this group.
- # @option attributes name [String] The name of the group.
+ # @option attributes name [String|Symbol] The name of the group.
# @option attributes repository
# [Vedeu::Repositories::Repository]
# The storage for all Group models.
# @option attributes visible [Boolean] Whether the group is
# visible or not.
@@ -41,11 +47,11 @@
# @param member [String]
# @return [Vedeu::Groups::Group]
def add(member)
attrs = attributes.merge!(members: members.add(member))
- Vedeu::Groups::Group.new(attrs).store
+ Vedeu::Groups::Group.store(attrs)
end
# Returns the attributes of the group.
#
# @return [Hash<Symbol => void>]
@@ -64,10 +70,20 @@
# @return [Array<String>]
def by_zindex
interfaces.sort { |a, b| a.zindex <=> b.zindex }.map(&:name)
end
+ # An object is equal when its values are the same.
+ #
+ # @param other [Vedeu::Groups::Group]
+ # @return [Boolean]
+ def eql?(other)
+ self.class == other.class && name == other.name &&
+ members == other.members
+ end
+ alias_method :==, :eql?
+
# 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.
#
# @note
@@ -100,20 +116,20 @@
# @param member [String]
# @return [Vedeu::Groups::Group]
def remove(member)
attrs = attributes.merge!(members: members.delete(member))
- Vedeu::Groups::Group.new(attrs).store
+ Vedeu::Groups::Group.store(attrs)
end
# Remove all members from the group.
#
# @return [Vedeu::Groups::Group]
def reset
attrs = defaults.merge!(name: name)
- Vedeu::Groups::Group.new(attrs).store
+ Vedeu::Groups::Group.store(attrs)
end
# Show the named group of interfaces, or without a name, the
# group of the currently focussed interface.
#
@@ -152,7 +168,15 @@
end
end # Group
end # Groups
+
+ # @!method hide_group
+ # @see Vedeu::Toggleable::ClassMethods#hide
+ # @!method show_group
+ # @see Vedeu::Toggleable::ClassMethods#show
+ # @!method toggle_group
+ # @see Vedeu::Toggleable::ClassMethods#toggle
+ def_delegators Vedeu::Groups::Group, :hide_group, :show_group, :toggle_group
end # Vedeu