Class: Log

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/forgetful-git/common/log.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log) ⇒ Log

Returns a new instance of Log.



9
10
11
12
13
14
15
# File 'lib/forgetful-git/common/log.rb', line 9

def initialize(log)
    date, repo, message = log.split("::")
    @timestamp = date
    @date = DateTime.strptime(date,'%s').strftime("%Y-%m-%d %H:%M").to_s.yellow
    @repo = repo.green
    @message = message
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



7
8
9
# File 'lib/forgetful-git/common/log.rb', line 7

def date
  @date
end

#messageObject (readonly)

Returns the value of attribute message.



7
8
9
# File 'lib/forgetful-git/common/log.rb', line 7

def message
  @message
end

#repoObject (readonly)

Returns the value of attribute repo.



7
8
9
# File 'lib/forgetful-git/common/log.rb', line 7

def repo
  @repo
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



7
8
9
# File 'lib/forgetful-git/common/log.rb', line 7

def timestamp
  @timestamp
end

Class Method Details

.pretty_print(logs) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/forgetful-git/common/log.rb', line 21

def self.pretty_print(logs)
    logSubset = Log.sorted_subset(logs)
    longest = Log.longest(logSubset)
    logSubset.each do |log|
        printf("%s %-#{longest}s: %s\n", log.date, log.repo, log.message)
    end
end

Instance Method Details

#<=>(other) ⇒ Object



17
18
19
# File 'lib/forgetful-git/common/log.rb', line 17

def <=>(other)
    other.timestamp <=> timestamp
end