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)


224
225
226
227
# File 'lib/store/digest.rb', line 224

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.



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

def bytes
  @bytes
end

#ctimeObject (readonly)

Returns the value of attribute ctime.



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

def ctime
  @ctime
end

#deletedObject (readonly)

Returns the value of attribute deleted.



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

def deleted
  @deleted
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



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

def mtime
  @mtime
end

#objectsObject (readonly)

Returns the value of attribute objects.



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

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.



231
232
233
234
235
236
237
238
239
240
# File 'lib/store/digest.rb', line 231

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



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/store/digest.rb', line 242

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.



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/store/digest.rb', line 261

def to_s

  out = "\#{self.class}\n  Statistics:\nCreated:         \#{@ctime}\nLast modified:   \#{@mtime}\nTotal objects:   \#{@objects}\nDeleted records: \#{@deleted}\nRepository size: \#{human_size}\n  EOT\n\n  %i[types languages charsets encodings].each do |k|\n    stats = instance_variable_get(\"@\#{k}\")\n    if stats and !stats.empty?\n      out << \"  \#{LABELS.fetch k, k.capitalize}: \#{stats.count}\\n\"\n      stats.keys.sort.each do |s|\n        out << \"    \#{s}: \#{stats[s]}\\n\"\n      end\n    end\n  end\n\n  out\nend\n"