Class: Torrent

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

Defined Under Namespace

Classes: Info

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(img) ⇒ Torrent

Returns a new instance of Torrent.



45
46
47
48
49
50
# File 'lib/immutablebox.rb', line 45

def initialize(img)
  torrent = BEncode.load(img)
  @announce = torrent['announce']
  @creation_date = torrent['creation date']
  @info = Info.new(torrent['info'])
end

Instance Attribute Details

#announceObject (readonly)

Returns the value of attribute announce.



54
55
56
# File 'lib/immutablebox.rb', line 54

def announce
  @announce
end

#creation_dateObject (readonly)

Returns the value of attribute creation_date.



53
54
55
# File 'lib/immutablebox.rb', line 53

def creation_date
  @creation_date
end

#infoObject (readonly)

Returns the value of attribute info.



52
53
54
# File 'lib/immutablebox.rb', line 52

def info
  @info
end

Class Method Details

.str2hex(str) ⇒ Object



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

def self.str2hex(str)
  str.unpack('C*').map{|v|"%02x" % v}.join
end

Instance Method Details

#inspectObject



60
61
62
# File 'lib/immutablebox.rb', line 60

def inspect
  @info.inspect
end

#to_sObject



56
57
58
# File 'lib/immutablebox.rb', line 56

def to_s
  "%s&tr=%s" % [@info.to_s, CGI.escape(@announce)]
end