Class: Store::Digest::Stats

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

Overview

This class represents a set of rudimentary statistics for the contents of the store.

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)


442
443
444
445
# File 'lib/store/digest.rb', line 442

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.



436
437
438
# File 'lib/store/digest.rb', line 436

def bytes
  @bytes
end

#ctimeObject (readonly)

Returns the value of attribute ctime.



436
437
438
# File 'lib/store/digest.rb', line 436

def ctime
  @ctime
end

#deletedObject (readonly)

Returns the value of attribute deleted.



436
437
438
# File 'lib/store/digest.rb', line 436

def deleted
  @deleted
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



436
437
438
# File 'lib/store/digest.rb', line 436

def mtime
  @mtime
end

#objectsObject (readonly)

Returns the value of attribute objects.



436
437
438
# File 'lib/store/digest.rb', line 436

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.



449
450
451
452
453
454
455
456
457
458
# File 'lib/store/digest.rb', line 449

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



460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/store/digest.rb', line 460

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.



479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/store/digest.rb', line 479

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