Class: Torrent::Info

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ Info

Returns a new instance of Info.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/immutablebox.rb', line 17

def initialize(info)
  @info = info
  @info_hash = Digest::SHA1.digest(BEncode.dump(info))
  @piece_length = info['piece length']
  @name = info['name']
  @files = info['files'] || [{
    'length' => info['length'], 'path' => [@name]
  }]
  pieces = info['pieces']
  @pieces = (pieces.size / 20).times.map{|i| pieces[i * 20, 20]}
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



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

def files
  @files
end

#infoObject (readonly)

Returns the value of attribute info.



29
30
31
# File 'lib/immutablebox.rb', line 29

def info
  @info
end

#info_hashObject (readonly)

Returns the value of attribute info_hash.



30
31
32
# File 'lib/immutablebox.rb', line 30

def info_hash
  @info_hash
end

#nameObject (readonly)

Returns the value of attribute name.



33
34
35
# File 'lib/immutablebox.rb', line 33

def name
  @name
end

#piece_lengthObject (readonly)

Returns the value of attribute piece_length.



32
33
34
# File 'lib/immutablebox.rb', line 32

def piece_length
  @piece_length
end

#piecesObject (readonly)

Returns the value of attribute pieces.



34
35
36
# File 'lib/immutablebox.rb', line 34

def pieces
  @pieces
end

Instance Method Details

#infohashObject



40
41
42
# File 'lib/immutablebox.rb', line 40

def infohash
  Torrent.str2hex(@info_hash)
end

#magnetObject



36
37
38
# File 'lib/immutablebox.rb', line 36

def magnet
  "magnet:?xt=urn:btih:%s" % Base32.encode(@info_hash)
end