Class: IRT::Log::Hunk

Inherits:
Array show all
Defined in:
lib/irt/hunks.rb

Direct Known Subclasses

FileHunk, InteractiveHunk

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header) ⇒ Hunk

Returns a new instance of Hunk.



8
9
10
# File 'lib/irt/hunks.rb', line 8

def initialize(header)
  @header = header
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



6
7
8
# File 'lib/irt/hunks.rb', line 6

def color
  @color
end

#headerObject (readonly)

Returns the value of attribute header.



6
7
8
# File 'lib/irt/hunks.rb', line 6

def header
  @header
end

Instance Method Details

#add_line(content, line_no) ⇒ Object



12
13
14
# File 'lib/irt/hunks.rb', line 12

def add_line(content, line_no)
  self << [content.chomp, line_no]
end

#header_nameObject



35
36
37
# File 'lib/irt/hunks.rb', line 35

def header_name
  @header
end

#inspectObject



49
50
51
# File 'lib/irt/hunks.rb', line 49

def inspect
  %(<#{self.class.name} #{header_name}>)
end

#last_line_noObject



31
32
33
# File 'lib/irt/hunks.rb', line 31

def last_line_no
  last && last[1]
end

#lines_strObject



27
28
29
# File 'lib/irt/hunks.rb', line 27

def lines_str
  map{|content, line_no| content }.join("\n")
end

#render(wanted = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/irt/hunks.rb', line 16

def render(wanted=nil)
  return unless size > 0
  Log.print_border
  render_header
  wanted ||= size
  last(wanted).each do |content, line_no|
    Log.print_border
    render_line(content, line_no)
  end
end

#render_headerObject



39
40
41
# File 'lib/irt/hunks.rb', line 39

def render_header
  puts IRT.dye("     #{header_name}     ",  "***** #{header_name} *****", color, :bold, :reversed)
end

#render_line(content, line_no) ⇒ Object



43
44
45
46
47
# File 'lib/irt/hunks.rb', line 43

def render_line(content, line_no)
  lcontent = IRT.dye content, color
  lno = IRT.dye(('%3d ' % line_no), color, :reversed)
  puts "#{lno} #{lcontent}"
end