Sha256: 81eb859c011dbdf3e5d1216a2c16c64f95994537e12edbe90e722c4e2057a082

Contents?: true

Size: 692 Bytes

Versions: 12

Compression:

Stored size: 692 Bytes

Contents

require 'calc'

# A simple calculator. This delegates all calculations to the 'calc'
# gem.
class Robut::Plugin::Calc
  include Robut::Plugin

  # Returns a description of how to use this plugin
  def usage
    "#{at_nick} calc <calculation> - replies with the result of <calculation>"
  end
  
  # Perform the calculation specified in +message+, and send the
  # result back.
  def handle(time, sender_nick, message)
    if sent_to_me?(message) && words(message).first == 'calc'
      calculation = words(message, 'calc').join(' ')
      begin
        reply("#{calculation} = #{::Calc.evaluate(calculation)}")
      rescue
        reply("Can't calculate that.")
      end
    end
  end

end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
sclemmer-robut-0.6.3 lib/robut/plugin/calc.rb
sclemmer-robut-0.6.2 lib/robut/plugin/calc.rb
sclemmer-robut-0.6.1 lib/robut/plugin/calc.rb
sclemmer-robut-0.6.0 lib/robut/plugin/calc.rb
sclemmer-robut-0.5.4 lib/robut/plugin/calc.rb
sclemmer-robut-0.5.3 lib/robut/plugin/calc.rb
sclemmer-robut-0.5.2 lib/robut/plugin/calc.rb
robut-0.5.2 lib/robut/plugin/calc.rb
robut-0.5.1 lib/robut/plugin/calc.rb
robut-0.5.0 lib/robut/plugin/calc.rb
robut-0.4.0 lib/robut/plugin/calc.rb
robut-0.3.0 lib/robut/plugin/calc.rb