Module: Elephrame::Trace
Instance Attribute Summary collapse
-
#grammar ⇒ Object
grammar is a hash { FILENAME => TRACERY RULES }.
Instance Method Summary collapse
-
#expand_and_post(text, *options) ⇒ Object
(also: #post)
a shortcut fuction for expanding text with tracery before posting.
-
#setup_tracery(*dirs) ⇒ Object
loads all of our tracery files into our
files
hash if a file is named ‘default’ then we load that intogrammar
.
Instance Attribute Details
#grammar ⇒ Object
grammar is a hash { FILENAME => TRACERY RULES }
9 10 11 |
# File 'lib/elephrame/mix/tracery.rb', line 9 def grammar @grammar end |
Instance Method Details
#expand_and_post(text, *options) ⇒ Object Also known as: post
a shortcut fuction for expanding text with tracery before posting
56 57 58 59 60 61 62 63 |
# File 'lib/elephrame/mix/tracery.rb', line 56 def (text, *) opts = Hash[*] rules = opts.fetch(:rules, 'default') actually_post(@grammar[rules].flatten(text), **opts.reject {|k| k == :rules }) end |
#setup_tracery(*dirs) ⇒ Object
loads all of our tracery files into our files
hash if a file is named ‘default’ then we load that into grammar
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/elephrame/mix/tracery.rb', line 17 def setup_tracery *dirs @grammar = {} dirs.each do |directory| Dir.open(directory) do |dir| dir.each do |file| # skip our current and parent dir next if file =~ /^\.\.?$/ # read the rule file into the files hash @grammar[file.split('.').first] = createGrammar(JSON.parse(File.read("#{directory}/#{file}"))) end end end # go ahead and makes a default mention-handler # if we have a reply rule file unless @grammar['reply'].nil? on_reply do |bot| bot.reply_with_mentions('#default#', rules: 'reply') end end end |