Module: BardBot
- Defined in:
- lib/bard_bot.rb,
lib/bard_bot/config.rb,
lib/bard_bot/dictionary.rb
Defined Under Namespace
Classes: Config, Dictionary
Constant Summary
collapse
- VERSION =
'1.0.0'
Class Method Summary
collapse
Class Method Details
.characters ⇒ Object
39
40
41
42
43
|
# File 'lib/bard_bot.rb', line 39
def characters
Dir[config.character_dir + '/*.txt'].map do |char|
char.split(File::SEPARATOR).last.sub('.txt', '').to_sym
end
end
|
.clear_dictionaries! ⇒ Object
31
32
33
|
# File 'lib/bard_bot.rb', line 31
def clear_dictionaries!
@dictionaries.clear
end
|
.config {|@config| ... } ⇒ Object
17
18
19
20
21
|
# File 'lib/bard_bot.rb', line 17
def config
@config ||= Config.new
yield @config if block_given?
@config
end
|
.dictionaries {|@dictionaries| ... } ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/bard_bot.rb', line 23
def dictionaries
@dictionaries ||= Hash.new do |h, char|
h[char] = Dictionary.new(config)
end
yield @dictionaries if block_given?
@dictionaries
end
|
.generate_sentence ⇒ Object
35
36
37
|
# File 'lib/bard_bot.rb', line 35
def generate_sentence
dictionaries[config.character].generate_sentence
end
|
.method_missing(meth) ⇒ Object
45
46
47
48
49
50
|
# File 'lib/bard_bot.rb', line 45
def method_missing(meth)
if /^generate_(?<num>\d+)_sentences$/ =~ meth.to_s
return Array.new.fill(0...num.to_i) { generate_sentence }.join
end
super
end
|