Sha256: eace80b49ac8e957b4f0798533ac0c842393db61ec57e2ce63c203112f299089

Contents?: true

Size: 643 Bytes

Versions: 2

Compression:

Stored size: 643 Bytes

Contents

# frozen_string_literal: true

require 'hahamut/message/base'
require 'hahamut/message/text'
require 'hahamut/message/image'
require 'hahamut/message/sticker'
require 'hahamut/message/command'
require 'Hahamut/message/bot_start'
require 'Hahamut/message/bot_event'

module Hahamut
  # Hahamut Message
  module Message
    class << self
      def types
        @types ||= (constants - [:Base]).map { |name| const_get(name) }
      end

      def parse(message)
        # TODO: Improve type match
        klass = types.find { |type| type.match?(message) }
        klass&.new(message['message'], message['sender_id'])
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hahamut-0.1.1 lib/hahamut/message.rb
hahamut-0.1.0 lib/hahamut/message.rb