Class: VCLog::ChangeLog
- Inherits:
-
Object
- Object
- VCLog::ChangeLog
- Includes:
- Enumerable
- Defined in:
- lib/vclog/changelog.rb
Overview
A ChangeLog encapsulates a list of Change objects.
Constant Summary collapse
- DAY =
Seconds in a day.
24*60*60
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Array of Change or ChangePoint instances.
Instance Method Summary collapse
-
#<<(entry) ⇒ Object
And a change to the changelog.
-
#above(level) ⇒ Object
Return a new changelog with entries having a level higer or equal to the given level.
-
#after(date_limit) ⇒ Object
Return a new changelog with entries occuring after the given date limit.
-
#before(date_limit) ⇒ Object
Return a new changelog with entries occuring before the given date limit.
- #by_author ⇒ Object
- #by_date ⇒ Object
- #by_type ⇒ Object
-
#change(data = {}) ⇒ Object
Add a change entry to the log.
-
#each(&block) ⇒ Object
Iterate over each change.
-
#empty? ⇒ Boolean
Is the changelog void of any changes?.
-
#initialize(changes = nil) ⇒ ChangeLog
constructor
Setup new ChangeLog instance.
-
#size ⇒ Object
Return the number of changes in the changelog.
-
#sort!(&block) ⇒ Object
Sort changes in place.
-
#to_h ⇒ Array<Hash>
Convert to list of hash.
Constructor Details
#initialize(changes = nil) ⇒ ChangeLog
Setup new ChangeLog instance.
30 31 32 33 |
# File 'lib/vclog/changelog.rb', line 30 def initialize(changes=nil) @changes = [] @changes = changes if changes end |
Instance Attribute Details
#changes ⇒ Object (readonly)
Array of Change or ChangePoint instances.
22 23 24 |
# File 'lib/vclog/changelog.rb', line 22 def changes @changes end |
Instance Method Details
#<<(entry) ⇒ Object
And a change to the changelog.
83 84 85 86 87 88 89 90 |
# 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) ⇒ Object
Return a new changelog with entries having a level higer or equal to the given level.
96 97 98 99 |
# 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) ⇒ Object
Return a new changelog with entries occuring after the given date limit.
105 106 107 108 |
# 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) ⇒ Object
Return a new changelog with entries occuring before the given date limit.
114 115 116 117 |
# 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 ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'lib/vclog/changelog.rb', line 136 def mapped = {} changes.each do |entry| mapped[entry.] ||= self.class.new mapped[entry.] << entry end mapped end |
#by_date ⇒ Object
146 147 148 149 150 151 152 153 154 |
# 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 ⇒ Object
126 127 128 129 130 131 132 133 |
# 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 = {}) ⇒ Object
Add a change entry to the log.
48 49 50 |
# File 'lib/vclog/changelog.rb', line 48 def change(data={}) @changes << Change.new(data) end |
#each(&block) ⇒ Object
Iterate over each change.
62 63 64 |
# File 'lib/vclog/changelog.rb', line 62 def each(&block) changes.each(&block) end |
#empty? ⇒ Boolean
Is the changelog void of any changes?
69 70 71 |
# File 'lib/vclog/changelog.rb', line 69 def empty? changes.empty? end |
#size ⇒ Object
Return the number of changes in the changelog.
76 77 78 |
# File 'lib/vclog/changelog.rb', line 76 def size changes.size end |
#sort!(&block) ⇒ Object
Sort changes in place.
55 56 57 |
# File 'lib/vclog/changelog.rb', line 55 def sort!(&block) changes.sort!(&block) end |
#to_h ⇒ Array<Hash>
Not a Hash! Need to rename method.
Convert to list of hash.
173 174 175 |
# File 'lib/vclog/changelog.rb', line 173 def to_h map{ |change| change.to_h } end |