Class: TelegramMeetupBot::MessageParser

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram_meetup_bot/message_parser.rb

Defined Under Namespace

Classes: User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ MessageParser

Returns a new instance of MessageParser.



6
7
8
# File 'lib/telegram_meetup_bot/message_parser.rb', line 6

def initialize(message)
  @message = message
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'lib/telegram_meetup_bot/message_parser.rb', line 3

def message
  @message
end

Instance Method Details

#authorObject



10
11
12
13
# File 'lib/telegram_meetup_bot/message_parser.rb', line 10

def author
  from = message.from
  User.new(from.id, from.username, from.first_name)
end

#commandObject



15
16
17
18
19
20
# File 'lib/telegram_meetup_bot/message_parser.rb', line 15

def command
  parse_message do |words|
    cmd, bot_name = words.first.split('@')
    cmd if bot_name.nil? || bot_name == Initializers::ConfigLoader.bot_name
  end
end

#paramsObject



22
23
24
# File 'lib/telegram_meetup_bot/message_parser.rb', line 22

def params
  parse_message { |words| words.drop(1) } || []
end