Sha256: 19ed5374cc369d26f1b07c60e617628c4055eb6b7855d3b0802c07c5aff49c75

Contents?: true

Size: 498 Bytes

Versions: 1

Compression:

Stored size: 498 Bytes

Contents

module Fossyl
  InvalidBencoding = Class.new(StandardError)

  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

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

require "fossyl/parser"

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fossyl-0.5.1 lib/fossyl.rb