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.
219 220 221 222 |
# File 'lib/store/digest.rb', line 219 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.
213 214 215 |
# File 'lib/store/digest.rb', line 213 def bytes @bytes end |
#ctime ⇒ Object (readonly)
Returns the value of attribute ctime.
213 214 215 |
# File 'lib/store/digest.rb', line 213 def ctime @ctime end |
#deleted ⇒ Object (readonly)
Returns the value of attribute deleted.
213 214 215 |
# File 'lib/store/digest.rb', line 213 def deleted @deleted end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
213 214 215 |
# File 'lib/store/digest.rb', line 213 def mtime @mtime end |
#objects ⇒ Object (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_size ⇒ String
Return a human-readable byte size.
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_struct ⇒ Object
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_s ⇒ String
Return the stats object as a nicely formatted string.
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 |