Sha256: 28a92da625299e2d668616249734e7e47f724cae9a608131790fe0aee526f749

Contents?: true

Size: 761 Bytes

Versions: 4

Compression:

Stored size: 761 Bytes

Contents

# frozen_string_literal: true
module I18n::Tasks
  module Stats
    def forest_stats(forest)
      key_count    = forest.leaves.count
      locale_count = forest.count
      if key_count.zero?
        {key_count: 0}
      else
        {
            locales:          forest.map(&:key).join(', '),
            key_count:        key_count,
            locale_count:     locale_count,
            per_locale_avg:   forest.inject(0) { |sum, f| sum + f.leaves.count } / locale_count,
            key_segments_avg: '%.1f' % (forest.leaves.inject(0) { |sum, node| sum + node.walk_to_root.count - 1 } / key_count.to_f),
            value_chars_avg:  forest.leaves.inject(0) { |sum, node| sum + node.value.to_s.length } / key_count
        }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
i18n-tasks-0.9.6 lib/i18n/tasks/stats.rb
i18n-tasks-0.9.5 lib/i18n/tasks/stats.rb
i18n-tasks-0.9.4 lib/i18n/tasks/stats.rb
i18n-tasks-0.9.3 lib/i18n/tasks/stats.rb