Method: Cog::Embeds#gather_from_file

Defined in:
lib/cog/embeds.rb

#gather_from_file(filename, opt = {}) ⇒ Hash

Returns mapping from hooks to { 'filename' => count } hashes.

Options Hash (opt):

  • :hash (Hash) — default: {}

    object in which to gather the mapping

  • :type (String) — default: 'cog'

    one of 'cog' or 'keep'



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cog/embeds.rb', line 56

def gather_from_file(filename, opt={})
  bucket = opt[:hash] || {}
  type = opt[:type] || 'cog'
  lang = Cog.language_for filename
  File.read(filename).scan(statement type, '[-A-Za-z0-9_.]+', :lang => lang) do |m|
    hook = m[0]
    bucket[hook] ||= {}
    bucket[hook][filename] ||= 0
    bucket[hook][filename] += 1
  end
  bucket
end