Class: CeilingCat::Plugin::Calc
- Inherits:
-
Base
- Object
- Base
- CeilingCat::Plugin::Calc
show all
- Defined in:
- lib/ceiling_cat/plugins/calc.rb
Instance Attribute Summary
Attributes inherited from Base
#event
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#body, #body_without_command, #body_without_nick, #body_without_nick_or_command, #commands, #handle, #initialize, #pluralize, #reply, #room, store, #store, #user, #words
Class Method Details
.commands ⇒ Object
4
5
6
|
# File 'lib/ceiling_cat/plugins/calc.rb', line 4
def self.commands
[{:command => "calculate", :description => "Performs basic math functions - '!calculate 7*5'", :method => "calculate", :public => true}]
end
|
.description ⇒ Object
8
9
10
|
# File 'lib/ceiling_cat/plugins/calc.rb', line 8
def self.description
"A basic calculator, for all your mathin' needs!"
end
|
.name ⇒ Object
12
13
14
|
# File 'lib/ceiling_cat/plugins/calc.rb', line 12
def self.name
"Calculator"
end
|
.public? ⇒ Boolean
16
17
18
|
# File 'lib/ceiling_cat/plugins/calc.rb', line 16
def self.public?
true
end
|
Instance Method Details
#calculate ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/ceiling_cat/plugins/calc.rb', line 20
def calculate
begin
math = body.gsub(/[^\d+-\/*\(\)\.]/,"") if math.length > 0 && math =~ /^\d.+\d$/
reply "#{math} = #{eval math}"
else
reply "I don't think that's an equation. Want to try something else?"
end
rescue => e
raise e
end
end
|