Class: Store::Digest::Stats
- Inherits:
-
Object
- Object
- Store::Digest::Stats
- Defined in:
- lib/store/digest.rb
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
-
#ctime ⇒ Object
readonly
Returns the value of attribute ctime.
-
#deleted ⇒ Object
readonly
Returns the value of attribute deleted.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
Instance Method Summary collapse
-
#human_size ⇒ String
Return a human-readable byte size.
-
#initialize(**options) ⇒ Stats
constructor
At this juncture the constructor just puts whatever you throw at it into the object.
- #label_struct ⇒ Object
-
#to_s ⇒ String
Return the stats object as a nicely formatted string.
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.
224 225 226 227 |
# File 'lib/store/digest.rb', line 224 def initialize ** # XXX help i am so lazy .each { |k, v| instance_variable_set "@#{k}", v } end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
218 219 220 |
# File 'lib/store/digest.rb', line 218 def bytes @bytes end |
#ctime ⇒ Object (readonly)
Returns the value of attribute ctime.
218 219 220 |
# File 'lib/store/digest.rb', line 218 def ctime @ctime end |
#deleted ⇒ Object (readonly)
Returns the value of attribute deleted.
218 219 220 |
# File 'lib/store/digest.rb', line 218 def deleted @deleted end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
218 219 220 |
# File 'lib/store/digest.rb', line 218 def mtime @mtime end |
#objects ⇒ Object (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_size ⇒ String
Return a human-readable byte size.
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_struct ⇒ Object
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_s ⇒ String
Return the stats object as a nicely formatted string.
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" |