class Ruboty::Actions::Rhymer::Hearing
Public Instance Methods
call(store)
click to toggle source
# File lib/ruboty/actions/rhymer/hearing.rb, line 7 def call(store) store.concat split_message(message.original[:body]) rhyme = try_rhymer(store) return unless rhyme store.clear options = {} unless ENV['RHYMER_OVERRIDE_TO'].to_s.empty? options[:to] = ENV['RHYMER_OVERRIDE_TO'] end message.reply(generate_reply(rhyme), options) end
Private Instance Methods
generate_reply(rhyme)
click to toggle source
# File lib/ruboty/actions/rhymer/hearing.rb, line 27 def generate_reply(rhyme) buf = [] buf.push 'Yo!' buf.push rhyme[0] buf.push rhyme[1] buf.join(' ') end
score_border()
click to toggle source
# File lib/ruboty/actions/rhymer/hearing.rb, line 41 def score_border (ENV['RHYMER_SCORE'] || 10).to_i end
split_message(str)
click to toggle source
# File lib/ruboty/actions/rhymer/hearing.rb, line 21 def split_message(str) str .split(/[[:space:]。!?\.]+/) .select { |n| n.size >= 4 } end
try_rhymer(messages)
click to toggle source
# File lib/ruboty/actions/rhymer/hearing.rb, line 35 def try_rhymer(messages) ::Rhymer::Parser.new(messages.join("。\n")).rhymes.select do |rhyme| rhyme.last >= score_border end.sample end