Sha256: cbe469a98d11abcdf637b6dffe94495582993d9ce7841637d189709267564208

Contents?: true

Size: 542 Bytes

Versions: 5

Compression:

Stored size: 542 Bytes

Contents

# encoding: UTF-8

module BEncodr
  module Integer
    def bencode
      Integer.bencode(self)
    end
    
    def self.bencode(intable)
      int = coerce(intable)
      
      [:i, int, :e].join
    end
    
    private
    
    def self.coerce(intable)
      if intable.respond_to?(:to_i)
        intable.to_i
      elsif intable.respond_to?(:to_int)
        intable.to_int
      else
        raise BEncodeError, "BEncodr::Integer.bencode can only be called on an object that provides a to_i or to_int method."
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bencodr-3.0.2 lib/bencodr/integer.rb
bencodr-3.0.1 lib/bencodr/integer.rb
bencodr-2.0.1 lib/bencodr/integer.rb
bencodr-3.0.0 lib/bencodr/integer.rb
bencodr-2.0.0 lib/bencodr/integer.rb