class Forematter::Commands::Count

Public Instance Methods

run() click to toggle source
# File lib/forematter/commands/count.rb, line 11
def run
  counts = tags.reduce({}) { |a, e| a.merge(e => (a[e] || 0) + 1) }
  fmt    = format(counts)

  counts.sort_by { |tag, count| count }.each do |tag, count|
    puts sprintf(fmt, count, tag)
  end
end

Protected Instance Methods

format(counts) click to toggle source
# File lib/forematter/commands/count.rb, line 26
def format(counts)
  "%#{counts.values.max.to_s.length}d %s"
end
tags() click to toggle source
# File lib/forematter/commands/count.rb, line 22
def tags
  files_with(field).map { |file| file[field].to_ruby }.flatten.map(&:to_sym)
end