Class: Butler::Plugin::Mapper
- Inherits:
-
Object
- Object
- Butler::Plugin::Mapper
- Defined in:
- lib/butler/plugin/mapper.rb
Instance Attribute Summary collapse
-
#authorization ⇒ Object
readonly
Returns the value of attribute authorization.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#plugin ⇒ Object
readonly
Returns the value of attribute plugin.
-
#trigger ⇒ Object
readonly
Returns the value of attribute trigger.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #abort_invocations? ⇒ Boolean
- #call(message, params) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(plugin, meth, language, expression) ⇒ Mapper
constructor
A new instance of Mapper.
- #invoked_by?(message) ⇒ Boolean
- #priority ⇒ Object
Constructor Details
#initialize(plugin, meth, language, expression) ⇒ Mapper
Returns a new instance of Mapper.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/butler/plugin/mapper.rb', line 25 def initialize(plugin, meth, language, expression) @plugin = plugin @method = meth @language = language @expression = expression @trigger = expression[/^\w+/].downcase @captures = [] @authorization = "plugin/#{@plugin.base}".freeze @name = "mapper:#{@language}:#{@expression}".freeze @hash = @name.hash tiles = expression.strip.scan(/(?:^|\s)[:*]\w+(?:\[[^\]]+\])?|\S+/).map { |word| word.strip! case word when /:(\w+)(.*)/ @captures << [$1.to_sym, $2] '(\S+)' when /\*(\w+)(.*)/ @captures << [$1.to_sym, $2] '(\S+(?:\s+\S+)*?)' else Regexp.escape(word) end } @regexp = Regexp.new('^'+tiles.join('\s+')+'$') end |
Instance Attribute Details
#authorization ⇒ Object (readonly)
Returns the value of attribute authorization.
17 18 19 |
# File 'lib/butler/plugin/mapper.rb', line 17 def @authorization end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
18 19 20 |
# File 'lib/butler/plugin/mapper.rb', line 18 def hash @hash end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
19 20 21 |
# File 'lib/butler/plugin/mapper.rb', line 19 def language @language end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/butler/plugin/mapper.rb', line 20 def name @name end |
#plugin ⇒ Object (readonly)
Returns the value of attribute plugin.
21 22 23 |
# File 'lib/butler/plugin/mapper.rb', line 21 def plugin @plugin end |
#trigger ⇒ Object (readonly)
Returns the value of attribute trigger.
22 23 24 |
# File 'lib/butler/plugin/mapper.rb', line 22 def trigger @trigger end |
Instance Method Details
#<=>(other) ⇒ Object
72 73 74 |
# File 'lib/butler/plugin/mapper.rb', line 72 def <=>(other) -10 <=> other.priority end |
#abort_invocations? ⇒ Boolean
76 77 78 |
# File 'lib/butler/plugin/mapper.rb', line 76 def abort_invocations? true end |
#call(message, params) ⇒ Object
64 65 66 |
# File 'lib/butler/plugin/mapper.rb', line 64 def call(, params) @plugin.new().send(@method, params) end |
#eql?(other) ⇒ Boolean
80 81 82 |
# File 'lib/butler/plugin/mapper.rb', line 80 def eql?(other) other.kind_of?(Mapper) && @name.eql?(other.name) end |
#invoked_by?(message) ⇒ Boolean
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/butler/plugin/mapper.rb', line 52 def invoked_by?() if match = @regexp.match(.post_arguments[0]) then params = {} @captures.zip(match.captures) { |(name, valid), value| params[name] = value } [OpenStruct.new(params)] else nil end end |
#priority ⇒ Object
68 69 70 |
# File 'lib/butler/plugin/mapper.rb', line 68 def priority -10 end |