Sha256: d9812796ee3ca5dba2c7b8f27f9958e7c1ab4286760b9b19559765ee1fa65384

Contents?: true

Size: 1.73 KB

Versions: 14

Compression:

Stored size: 1.73 KB

Contents

module Vedeu

  # Interfaces can be associated with one another by being members of the same
  # Group. A Group is a collection of interface names.
  class Group

    include Vedeu::Model

    # @!attribute [rw] name
    # @return [String]
    attr_accessor :name

    # Return a new instance of Vedeu::Group.
    #
    # @param attributes [Hash]
    # @option attributes members [Array] A collection of names of interfaces
    #   belonging to this group.
    # @option attributes name [String] The name of the group.
    # @option attributes repository [Vedeu::Repository] The storage for all
    #   Group models.
    # @return [Group]
    def initialize(attributes = {})
      @attributes = defaults.merge!(attributes)

      @members    = Array(@attributes[:members])
      @name       = @attributes[:name]
      @repository = @attributes[:repository]
    end

    # Add a member to the group by name.
    #
    # @param member [String]
    # @return [Group]
    def add(member)
      @members = members.add(member)

      Vedeu::Group.new(name: name, members: @members).store
    end

    # Return the members as a Set.
    #
    # @return [Set]
    def members
      @members.to_set
    end

    # Remove a member from the group by name.
    #
    # @param member [String]
    # @return [Group]
    def remove(member)
      @members = members.delete(member)

      Vedeu::Group.new(name: name, members: @members).store
    end

    # Remove all members from the group.
    #
    # @return [Group]
    def reset
      Vedeu::Group.new(defaults.merge!(name: name)).store
    end

    private

    # @return [Hash]
    def defaults
      {
        members:    [],
        name:       '',
        repository: Vedeu.groups,
      }
    end

  end # Group

end # Vedeu

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
vedeu-0.4.32 lib/vedeu/models/group.rb
vedeu-0.4.31 lib/vedeu/models/group.rb
vedeu-0.4.30 lib/vedeu/models/group.rb
vedeu-0.4.29 lib/vedeu/models/group.rb
vedeu-0.4.28 lib/vedeu/models/group.rb
vedeu-0.4.27 lib/vedeu/models/group.rb
vedeu-0.4.26 lib/vedeu/models/group.rb
vedeu-0.4.25 lib/vedeu/models/group.rb
vedeu-0.4.24 lib/vedeu/models/group.rb
vedeu-0.4.23 lib/vedeu/models/group.rb
vedeu-0.4.22 lib/vedeu/models/group.rb
vedeu-0.4.21 lib/vedeu/models/group.rb
vedeu-0.4.20 lib/vedeu/models/group.rb
vedeu-0.4.19 lib/vedeu/models/group.rb