summaryrefslogtreecommitdiff
path: root/bocelli/base.rb
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-08-18 22:29:55 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-08-18 22:29:55 -0700
commit597840b750de571ee87dd34806fe5f188f45d667 (patch)
tree63962371c8fbac61fd88abfbbcae22dae079b5b1 /bocelli/base.rb
parent2af0cbd96d523b9ed6c4489e2dc71ca23c757d42 (diff)
downloadbocelli-597840b750de571ee87dd34806fe5f188f45d667.tar.gz
bocelli-597840b750de571ee87dd34806fe5f188f45d667.tar.xz
Cleanup and less duplication.
Diffstat (limited to 'bocelli/base.rb')
-rw-r--r--bocelli/base.rb28
1 files changed, 14 insertions, 14 deletions
diff --git a/bocelli/base.rb b/bocelli/base.rb
index 990a819..bc7e617 100644
--- a/bocelli/base.rb
+++ b/bocelli/base.rb
@@ -34,8 +34,6 @@ module Bocelli
end
def on(route, &block)
- name = "route #{route.inspect}"
-
@routes[route] = block
end
@@ -43,7 +41,7 @@ module Bocelli
@modules[mod.name[/[^:]+$/].downcase.intern] ||= mod
end
- def match(str, route)
+ def match?(str, route)
case route
when Regexp
str =~ route
@@ -52,6 +50,18 @@ module Bocelli
end
end
+ def match(str)
+ @routes.detect { |k, _| match?(str, k) }
+ end
+
+ def mod_match(str)
+ if str =~ /\A(\S+) (.*)/
+ if (mod = Hash[@modules.map { |k, v| [k.to_s, v] }][$1])
+ mod.match($2)
+ end
+ end
+ end
+
def process(str)
if str =~ /\A:?(\S+) PRIVMSG (\S+) :?(.*)/
metadata = {
@@ -60,17 +70,7 @@ module Bocelli
message: $3
}
- if $3 =~ /\A(\S+) (.*)/
- if (mod = Hash[@modules.map { |k, v| [k.to_s, v] }][$1])
- if (match = mod.match($2))
- route, block = match
-
- return new(str, route, block, metadata).execute
- end
- end
- end
-
- if (match = @routes.detect { |k, _| match(metadata[:message], k) })
+ if (match = match($3)) || (match = mod_match($3))
route, block = match
new(str, route, block, metadata).execute