Class: Store::Digest::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/store/digest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Stats

At this juncture the constructor just puts whatever you throw at it into the object. See Meta::LMDB#meta_get_stats for the real magic.

Parameters:

  • options (Hash)


219
220
221
222
# File 'lib/store/digest.rb', line 219

def initialize **options
  # XXX help i am so lazy
  options.each { |k, v| instance_variable_set "@#{k}", v }
end

Instance Attribute Details

#bytesObject (readonly)

Returns the value of attribute bytes.



213
214
215
# File 'lib/store/digest.rb', line 213

def bytes
  @bytes
end

#ctimeObject (readonly)

Returns the value of attribute ctime.



213
214
215
# File 'lib/store/digest.rb', line 213

def ctime
  @ctime
end

#deletedObject (readonly)

Returns the value of attribute deleted.



213
214
215
# File 'lib/store/digest.rb', line 213

def deleted
  @deleted
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



213
214
215
# File 'lib/store/digest.rb', line 213

def mtime
  @mtime
end

#objectsObject (readonly)

Returns the value of attribute objects.



213
214
215
# File 'lib/store/digest.rb', line 213

def objects
  @objects
end

Instance Method Details

#human_sizeString

Return a human-readable byte size.

Returns:

  • (String)

    a representation of the byte size of the store.



226
227
228
229
230
231
232
233
234
235
# File 'lib/store/digest.rb', line 226

def human_size
  # the deci-magnitude also happens to conveniently work as an array index
  mag  = @bytes == 0 ? 0 : (Math.log(@bytes, 2) / 10).floor
  if mag > 0
    '%0.2f %s (%d bytes)' % [(@bytes.to_f / 2**(mag * 10)).round(2),
      MAGNITUDES[mag], @bytes]
  else
    "#{@bytes} bytes"
  end
end

#label_structObject



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/store/digest.rb', line 237

def label_struct
  out = {}
  %i[types languages charsets encodings].each do |k|
    stats = instance_variable_get("@#{k}")
    if stats and !stats.empty?
      # XXX note that all these plurals are just inflected with
      # 's' so clipping off the last character is correct
      ks = k.to_s[0, k.to_s.length - 1].to_sym
      x = out[ks] ||= [LABELS.fetch(k, k.capitalize), {}]
      stats.keys.sort.each do |s|
        x.last[s] = stats[s]
      end
    end
  end
  out
end

#to_sString

Return the stats object as a nicely formatted string.

Returns:

  • (String)

    no joke.



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/store/digest.rb', line 256

def to_s

  out = <<-EOT
#{self.class}
  Statistics:
Created:         #{@ctime}
Last modified:   #{@mtime}
Total objects:   #{@objects}
Deleted records: #{@deleted}
Repository size: #{human_size}
  EOT

  %i[types languages charsets encodings].each do |k|
    stats = instance_variable_get("@#{k}")
    if stats and !stats.empty?
      out << "  #{LABELS.fetch k, k.capitalize}: #{stats.count}\n"
      stats.keys.sort.each do |s|
        out << "    #{s}: #{stats[s]}\n"
      end
    end
  end

  out
end