Class: PVN::Seek::Match

Inherits:
Object
  • Object
show all
Includes:
Logue::Loggable
Defined in:
lib/pvn/seek/match.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lnums, contents, previous_entry, current_entry) ⇒ Match

Returns a new instance of Match.



15
16
17
18
19
20
# File 'lib/pvn/seek/match.rb', line 15

def initialize lnums, contents, previous_entry, current_entry
  @lnums = lnums
  @contents = contents
  @previous_entry = previous_entry
  @current_entry = current_entry
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



11
12
13
# File 'lib/pvn/seek/match.rb', line 11

def contents
  @contents
end

#current_entryObject (readonly)

Returns the value of attribute current_entry.



12
13
14
# File 'lib/pvn/seek/match.rb', line 12

def current_entry
  @current_entry
end

#lnumsObject (readonly)

Returns the value of attribute lnums.



10
11
12
# File 'lib/pvn/seek/match.rb', line 10

def lnums
  @lnums
end

#previous_entryObject (readonly)

Returns the value of attribute previous_entry.



13
14
15
# File 'lib/pvn/seek/match.rb', line 13

def previous_entry
  @previous_entry
end

Instance Method Details

#decorate(path, fromrev, torev) ⇒ Object



26
27
28
# File 'lib/pvn/seek/match.rb', line 26

def decorate path, fromrev, torev
  [ path.to_s.color(:yellow), fromrev, torev ]
end

#diff(othermatch) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/pvn/seek/match.rb', line 54

def diff othermatch
  diff = Array.new
  lnums.each do |lnum|
    line = @contents[lnum]
    unless othermatch.has_line? line
      diff << [ lnum, line ]
    end
  end
  diff
end

#has_line?(line) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/pvn/seek/match.rb', line 50

def has_line? line
  @lnums.detect { |lnum| @contents[lnum].index line }
end

#linesObject



22
23
24
# File 'lib/pvn/seek/match.rb', line 22

def lines
  @lnums.collect { |lnum| @contents[lnum] }
end

#show(path, use_color) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/pvn/seek/match.rb', line 30

def show path, use_color
  # todo: run through entry formatter in log

  fromrev = current_entry.revision
  torev   = previous_entry.revision

  pathstr, fromrevstr, torevstr = use_color ? decorate(path, fromrev, torev) : [ path.to_s, fromrev, torev ]
  pathrev = "#{pathstr} -r#{fromrevstr}:#{torevstr}"
  $io.puts pathrev
  
  @lnums.each do |lnum|
    line = @contents[lnum]
    $io.puts "#{lnum + 1}: #{line}"
  end
end

#to_sObject



46
47
48
# File 'lib/pvn/seek/match.rb', line 46

def to_s
  "[#{lnums}]: #{lines}; prev: #{previous_entry && previous_entry.revision}; curr: #{current_entry && current_entry.revision}"
end