Class: Inventory::Licenses

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/inventory-1.0/licenses.rb

Overview

Contains zero or more licenses of the project. Licenses can be added and enumerated. Licenses are set up by passing a block to #initialize and calling #license inside it.

Examples:

Creating a List of Licenses

Licenses.new{
  license 'LGPLv3+',
          'GNU Lesser General Public License, version 3 or later',
          'http://www.gnu.org/licenses/'
  license 'GPLv3+',
          'GNU General Public License, version 3 or later',
          'http://www.gnu.org/licenses/'
}

Instance Method Summary collapse

Constructor Details

#initialize(*licenses) {|?| ... } ⇒ Licenses

Creates a new list of LICENSES and allows more to be added in the optionally #instance_exec’d block by calling #license inside it.

Parameters:

Yields:

  • (?)


24
25
26
27
# File 'lib/inventory-1.0/licenses.rb', line 24

def initialize(*licenses)
  @licenses = licenses
  instance_exec(&Proc.new) if block_given?
end

Instance Method Details

#+(other) ⇒ Licenses

Returns The authors of the receiver and those of OTHER.

Returns:

  • (Licenses)

    The authors of the receiver and those of OTHER



44
45
46
# File 'lib/inventory-1.0/licenses.rb', line 44

def +(other)
  self.class.new(*(licenses + other.licenses))
end

# {|license| ... } ⇒ Object #Enumerator<Author>

Overloads:

  • # {|license| ... } ⇒ Object

    Enumerates the licenses.

    Yield Parameters:

  • #Enumerator<Author>

    Returns An Enumerator over the licenses.

    Returns:

    • (Enumerator<Author>)

      An Enumerator over the licenses



54
55
56
57
58
59
60
# File 'lib/inventory-1.0/licenses.rb', line 54

def each
  return enum_for(__method__) unless block_given?
  licenses.each do |license|
    yield license
  end
  self
end