class VCLog::ChangeLog

A ChangeLog encapsulates a list of Change objects.

Constants

DAY

Seconds in a day.

Attributes

changes[R]

Array of Change or ChangePoint instances.

Public Class Methods

new(changes=nil) click to toggle source

Setup new ChangeLog instance.

@param [Array<Change>] changes

An array of Change objects.
# File lib/vclog/changelog.rb, line 30
def initialize(changes=nil)
  @changes = []
  @changes = changes if changes
end

Public Instance Methods

<<(entry) click to toggle source

And a change to the changelog.

# File lib/vclog/changelog.rb, line 83
def <<(entry)
  case entry
  when Change, ChangePoint
    @changes << entry
  else
    #raise "Not a Change ro ChangePoint instance - #{entry.inspect}"
  end
end
above(level) click to toggle source

Return a new changelog with entries having a level higer or equal to the given level.

# File lib/vclog/changelog.rb, line 96
def above(level)
  above = changes.select{ |entry| entry.level >= level }
  self.class.new(above)
end
after(date_limit) click to toggle source

Return a new changelog with entries occuring after the given date limit.

# File lib/vclog/changelog.rb, line 105
def after(date_limit)
  after = changes.select{ |entry| entry.date > date_limit + DAY }
  self.class.new(after)
end
before(date_limit) click to toggle source

Return a new changelog with entries occuring before the given date limit.

# File lib/vclog/changelog.rb, line 114
def before(date_limit)
  before = changes.select{ |entry| entry.date <= date_limit + DAY }
  self.class.new(before)
end
by_author() click to toggle source
# File lib/vclog/changelog.rb, line 136
def by_author
  mapped = {}
  changes.each do |entry|
    mapped[entry.author] ||= self.class.new
    mapped[entry.author] << entry
  end
  mapped
end
by_date() click to toggle source
# File lib/vclog/changelog.rb, line 146
def by_date
  mapped = {}
  changes.each do |entry|
    mapped[entry.date.strftime('%Y-%m-%d')] ||= self.class.new
    mapped[entry.date.strftime('%Y-%m-%d')] << entry
  end
  mapped = mapped.to_a.sort{ |a,b| b[0] <=> a[0] }
  mapped
end
by_type() click to toggle source
# File lib/vclog/changelog.rb, line 126
def by_type
  mapped = {}
  changes.each do |entry|
    mapped[entry.type] ||= self.class.new
    mapped[entry.type] << entry
  end
  mapped
end
change(data={}) click to toggle source

Add a change entry to the log.

# File lib/vclog/changelog.rb, line 48
def change(data={})
  @changes << Change.new(data)
end
each(&block) click to toggle source

Iterate over each change.

# File lib/vclog/changelog.rb, line 62
def each(&block)
  changes.each(&block)
end
empty?() click to toggle source

Is the changelog void of any changes?

# File lib/vclog/changelog.rb, line 69
def empty?
  changes.empty?
end
size() click to toggle source

Return the number of changes in the changelog.

# File lib/vclog/changelog.rb, line 76
def size
  changes.size
end
sort!(&block) click to toggle source

Sort changes in place.

# File lib/vclog/changelog.rb, line 55
def sort!(&block)
  changes.sort!(&block)
end
to_h() click to toggle source

Convert to list of hash.

@return [Array<Hash>]

@todo Not a Hash! Need to rename method.

# File lib/vclog/changelog.rb, line 173
def to_h
  map{ |change| change.to_h }
end