Class: BTCompare::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/btcompare/result.rb

Overview

Holds the result of a comparison. When Result is created its variables are writable. It is strongly encouraged that developers using this class run the method lock on the object as soon as the data has been set in the object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Result

Returns a new instance of Result.

Parameters:


19
20
21
22
23
# File 'lib/btcompare/result.rb', line 19

def initialize parent
	@parent = parent
	@same_piece_count = nil
	@difference_ids = nil
end

Instance Attribute Details

#difference_idsObject

Contains piece ids of differences


15
16
17
# File 'lib/btcompare/result.rb', line 15

def difference_ids
  @difference_ids
end

#same_piece_countObject

Files have same piece count


11
12
13
# File 'lib/btcompare/result.rb', line 11

def same_piece_count
  @same_piece_count
end

Instance Method Details

#diff_typesArray<Symbol>

Lists available types of diffs available to use on these torrent files.

Returns:

  • (Array<Symbol>)

    :notAvailable If torrent files are deemed too different to consider for diffing.


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/btcompare/result.rb', line 39

def diff_types
	available = []

	if @parent.file_1.contains_found? and @parent.file_2.contains_found? then
		available.push :direct
	end


	if available.empty? then
		available.push :notAvailable
	end
	return available
end

#lockObject

Locks instance variables for the object


27
28
29
30
31
32
# File 'lib/btcompare/result.rb', line 27

def lock
	self.instance_eval do 
		undef :same_piece_count=
		undef :difference_ids=
	end
end

#offsetsHash<Integer,Integer>

Gets the byte offset for the pieces that are different.

Returns:

  • (Hash<Integer,Integer>)

    Piece id => offset within file


56
57
58
59
60
61
62
63
# File 'lib/btcompare/result.rb', line 56

def offsets
	to_return = {}
	piece_length = @parent.file_1.piece_length
	@difference_ids.each do |id|
		to_return[id] = id * piece_length
	end
	return to_return
end