def to_h
      result = {}

      ## Extra fields added by this method:
      # Length of the torrent
      result[:dataLength] = @info ? @info.dataLength : 0
      # Percent complete
      pct = withCurrentAndTotalBytes{ |cur, total| (cur.to_f / total.to_f * 100.0).round 1 }
      result[:percentComplete] = pct
      # Time left
      secondsLeft = withCurrentAndTotalBytes do |cur, total|
        if @downloadRateDataOnly && @downloadRateDataOnly > 0
          (total.to_f - cur.to_f) / @downloadRateDataOnly 
        else
          0
        end
      end
      # Cap estimated time at 9999 hours
      secondsLeft = 35996400 if secondsLeft > 35996400
      result[:timeLeft] = Formatter.formatTime(secondsLeft)

      ## Regular fields
      result[:info] = @info ? @info.to_h : nil
      result[:infoHash] = @infoHash
      result[:recommendedName] = @recommendedName
      result[:downloadRate] = @downloadRate
      result[:uploadRate] = @uploadRate
      result[:downloadRateDataOnly] = @downloadRateDataOnly
      result[:uploadRateDataOnly] = @uploadRateDataOnly
      result[:completedBytes] = @completedBytes
      result[:peers] = @peers.collect{ |p| p.to_h }
      result[:state] = @state
      #result[:completePieceBitfield] = @completePieceBitfield
      result[:metainfoLength] = @metainfoLength
      result[:metainfoCompletedLength] = @metainfoCompletedLength
      result[:paused] = @paused
      result[:queued] = @queued
      result[:uploadRateLimit] = @uploadRateLimit
      result[:downloadRateLimit] = @downloadRateLimit
      result[:ratio] = @ratio
      result[:uploadDuration] = @uploadDuration
      result[:bytesUploaded] = @bytesUploaded
      result[:bytesDownloaded] = @bytesDownloaded
      result[:alarms] = @alarms.collect{ |a| a.to_h }

      result
    end
def to_h
      result = {}

      ## Extra fields added by this method:
      # Length of the torrent
      result[:dataLength] = @info ? @info.dataLength : 0
      # Percent complete
      pct = withCurrentAndTotalBytes{ |cur, total| (cur.to_f / total.to_f * 100.0).round 1 }
      result[:percentComplete] = pct
      # Time left
      secondsLeft = withCurrentAndTotalBytes do |cur, total|
        if @downloadRateDataOnly && @downloadRateDataOnly > 0
          (total.to_f - cur.to_f) / @downloadRateDataOnly 
        else
          0
        end
      end
      # Cap estimated time at 9999 hours
      secondsLeft = 35996400 if secondsLeft > 35996400
      result[:timeLeft] = Formatter.formatTime(secondsLeft)

      ## Regular fields
      result[:info] = @info ? @info.to_h : nil
      result[:infoHash] = @infoHash
      result[:recommendedName] = @recommendedName
      result[:downloadRate] = @downloadRate
      result[:uploadRate] = @uploadRate
      result[:downloadRateDataOnly] = @downloadRateDataOnly
      result[:uploadRateDataOnly] = @uploadRateDataOnly
      result[:completedBytes] = @completedBytes
      result[:peers] = @peers.collect{ |p| p.to_h }
      result[:state] = @state
      #result[:completePieceBitfield] = @completePieceBitfield
      result[:metainfoLength] = @metainfoLength
      result[:metainfoCompletedLength] = @metainfoCompletedLength
      result[:paused] = @paused
      result[:queued] = @queued
      result[:uploadRateLimit] = @uploadRateLimit
      result[:downloadRateLimit] = @downloadRateLimit
      result[:ratio] = @ratio
      result[:uploadDuration] = @uploadDuration
      result[:bytesUploaded] = @bytesUploaded
      result[:bytesDownloaded] = @bytesDownloaded
      result[:alarms] = @alarms.collect{ |a| a.to_h }

      result
    end
Convert to a hash. Also flattens some of the data into new fields.