Sha256: a072bc0608fc3083b60d655d96bfc65d7e85e0276a9e68a8729a436d6f08deb0

Contents?: true

Size: 873 Bytes

Versions: 4

Compression:

Stored size: 873 Bytes

Contents

module Boty
  class Action
    attr_reader :regex, :desc, :action

    class Description
      attr_reader :command, :description
      attr_writer :regex

      def initialize(command, description: nil, regex: nil)
        if description.nil?
          @description = command
        else
          @command, @description = command, description
        end

        @regex = regex
      end

      def command
        return @command if @command

        match = /\?(i?)-(mx|mix):(.*)\)/.match @regex.to_s
        "/#{match[3]}/#{match[1]}"
      end
    end

    def initialize(regex, desc, &action)
      desc = Hash(desc)
      description = Description.new(desc[:command],
                                    description: desc[:description],
                                    regex: regex)
      @regex, @desc, @action = regex, description, action
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
boty-0.0.12 lib/boty/action.rb
boty-0.0.11 lib/boty/action.rb
boty-0.0.10 lib/boty/action.rb
boty-0.0.9 lib/boty/action.rb