lib/meiou/book.rb in meiou-0.2.0 vs lib/meiou/book.rb in meiou-0.2.2

- old
+ new

@@ -102,11 +102,15 @@ def filter s, k a = [] @bin[s].transaction { |db| db.keys.map { |e| if Regexp.new(k).match(db[e]); a << e end } } return a end - + def map &b + BOOK.sizes.each do |size| + @bin[size].transaction { |db| db.keys.map { |e| b.call(db[e]) } } + end + end def each k, &b @bin[k].transaction { |db| db.keys.map { |e| b.call(db[e]) } } return nil end end @@ -166,10 +170,20 @@ BOOK.tag(word).each_pair { |k,v| if v != nil; v.sample(num[0] || 3).compact.uniq.shuffle.each { |e| a << { book: k, index: e, mood: BOOK[k].mood(e), text: BOOK[k][e] } }; end } a.flatten.sample(num[1] || num[0] || 3).compact.uniq.shuffle.each { |e| block.call(e) } return nil end + def self.to_a + a = [] + @@BOOK.each_pair { |k,v| v.map { |e| a << e }} + return a.compact + end + + def self.to_s + BOOK.to_a.join("\n\n") + end + def self.init! Dir['books/*'].each { |e| k = e.gsub("books/", "").gsub(".txt", "").gsub("_", " "); Meiou.log :init_scan, %[Scanning #{k}...] @@BOOK[k] @@ -185,9 +199,10 @@ @@BOOK[k].load(e) } Meiou.log :compile_done, %[done!] return "DONE!" end + end Meiou.compile(:book) { |h| BOOK.compile! } Meiou.init(:book) { |h| BOOK.init! }