Class: PVN::Log::SummaryFormatter

Inherits:
Formatter show all
Defined in:
lib/pvn/log/formatter/summary_formatter.rb

Constant Summary

Constants inherited from Formatter

Formatter::COLORS, Formatter::WIDTHS

Instance Attribute Summary collapse

Attributes inherited from Formatter

#use_colors

Instance Method Summary collapse

Methods inherited from Formatter

#colors, #width

Methods inherited from ColorFormatter

#add_field, #colorize, #pad

Constructor Details

#initialize(use_colors, entry, idx, from_head, from_tail, total) ⇒ SummaryFormatter

Returns a new instance of SummaryFormatter.



16
17
18
19
20
21
22
23
# File 'lib/pvn/log/formatter/summary_formatter.rb', line 16

def initialize use_colors, entry, idx, from_head, from_tail, total
  super use_colors
  @entry = entry
  @idx = idx
  @from_head = from_head
  @from_tail = from_tail
  @total = total
end

Instance Attribute Details

#entryObject (readonly)

Returns the value of attribute entry.



10
11
12
# File 'lib/pvn/log/formatter/summary_formatter.rb', line 10

def entry
  @entry
end

#from_headObject (readonly)

Returns the value of attribute from_head.



12
13
14
# File 'lib/pvn/log/formatter/summary_formatter.rb', line 12

def from_head
  @from_head
end

#from_tailObject (readonly)

Returns the value of attribute from_tail.



13
14
15
# File 'lib/pvn/log/formatter/summary_formatter.rb', line 13

def from_tail
  @from_tail
end

#idxObject (readonly)

Returns the value of attribute idx.



11
12
13
# File 'lib/pvn/log/formatter/summary_formatter.rb', line 11

def idx
  @idx
end

#totalObject (readonly)

Returns the value of attribute total.



14
15
16
# File 'lib/pvn/log/formatter/summary_formatter.rb', line 14

def total
  @total
end

Instance Method Details

#formatObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pvn/log/formatter/summary_formatter.rb', line 25

def format
  lines = add_field(entry.revision, :revision)
  negidx  = (-1 - idx).to_s

  if from_head
    lines << add_field(negidx, :neg_revision)
  else
    lines << pad("", :neg_revision)
  end

  if from_tail
    posidx = "+#{total - idx - 1}"
    lines << add_field(posidx, :pos_revision)
  else
    lines << pad("", :pos_revision)
  end
  
  lines << add_field(entry.author, :author)
  lines << colorize(entry.date, :date)
  lines
end