Module: Fossyl

Defined in:
lib/fossyl.rb,
lib/fossyl/version.rb

Constant Summary collapse

InvalidBencoding =
Class.new(StandardError)
VERSION =
"0.5.0"

Class Method Summary collapse

Class Method Details

.dump(object) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fossyl.rb', line 7

def self.dump(object)
  case object
  when String, Symbol
    "#{object.length}:#{object}"
  when Integer
    "i#{object}e"
  when Array
    list = object.map {|item| dump(item) }.join
    "l#{list}e"
  when Hash
    hash = object.sort.map {|key, value| dump(key) << dump(value) }.join
    "d#{hash}e"
  end
end

.load(string) ⇒ Object



22
23
24
# File 'lib/fossyl.rb', line 22

def self.load(string)
  Parser.new(string).parse
end