Sha256: db4854ea1b977a1ec7cb024bc846b590056a4765d5a5b24cbb229caa431a6703

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

module VCLog

  # A Release encapsulate a collection of 
  # Change objects associated to a Tag.
  class Release

    # Tag object this release represents.
    attr :tag

    # Array of Change objects.
    attr :changes

    # New Release object.
    #
    # tag    - Tag object
    # change - Array of Change objects
    #
    def initialize(tag, changes)
      @tag = tag
      @changes = changes
    end

    # Group +changes+ by type and sort by level.
    # Returns an associative array of [type, changes].
    def groups
      @groups ||= (
        changes.group_by{ |e| e.type }.sort{ |a,b| b[1][0].level <=> a[1][0].level }
      )
    end

    # Compare release by tag.
    def <=>(other)
      @tag <=> other.tag
    end

    # Convert Release to Hash.
    def to_h
      { 'version'  => tag.name,
        'date'     => tag.date,
        'message'  => tag.message,
        'author'   => tag.author,
        'revision' => tag.revision,
        'changes'  => changes.map{|change| change.to_h}
      }
    end

    #def to_json
    #  to_h.to_json
    #end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vclog-1.8.2 lib/vclog/release.rb
vclog-1.8.1 lib/vclog/release.rb
vclog-1.8.0 lib/vclog/release.rb
vclog-1.7.0 lib/vclog/release.rb
vclog-1.6.1 lib/vclog/release.rb
vclog-1.6.0 lib/vclog/release.rb