Module: BEncodr::Dictionary

Defined in:
lib/bencodr/dictionary.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.bencode(hashable) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/bencodr/dictionary.rb', line 9

def self.bencode(hashable)
  hash = coerce(hashable)
  
  hash.keys.sort{|a, b| a.to_s <=> b.to_s}.collect do |key|
    BEncodr::String.bencode(key.to_s) + Object.bencode(hash[key])
  end.unshift(:d).push(:e).join
end

Instance Method Details

#bencodeObject



5
6
7
# File 'lib/bencodr/dictionary.rb', line 5

def bencode
  Dictionary.bencode(self)
end