Class: Twitch::Bot::IrcMessageTags

Inherits:
Object
  • Object
show all
Defined in:
lib/twitch/bot/irc_message.rb

Overview

This class parses the tags portion in an IRC message. rubocop:disable Layout/LineLength <message> ::= [‘@’ <tags> <SPACE>] [‘:’ <prefix> <SPACE> ] <command> <params> <crlf> <tags> ::= <tag> [‘;’ <tag>]* <tag> ::= <key> [‘=’ <escaped_value>] <key> ::= [ <client_prefix> ] [ <vendor> ‘/’ ] <key_name> <client_prefix> ::= ‘+’ <key_name> ::= <non-empty sequence of ascii letters, digits, hyphens (‘-’)> <escaped_value> ::= <sequence of zero or more utf8 characters except NUL, CR, LF, semicolon (‘;`) and SPACE> <vendor> ::= <host> rubocop:enable Layout/LineLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_tags) ⇒ IrcMessageTags

Returns a new instance of IrcMessageTags.



19
20
21
22
# File 'lib/twitch/bot/irc_message.rb', line 19

def initialize(raw_tags)
  @raw_tags = raw_tags
  @tags = parse
end

Instance Attribute Details

#tagsObject (readonly)

Returns the value of attribute tags.



17
18
19
# File 'lib/twitch/bot/irc_message.rb', line 17

def tags
  @tags
end

Instance Method Details

#[](key) ⇒ Object



24
25
26
# File 'lib/twitch/bot/irc_message.rb', line 24

def [](key)
  @tags[key]
end

#boolean_state(key, name) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/twitch/bot/irc_message.rb', line 43

def boolean_state(key, name)
  return unless tags.key?(key)

  case tags[key]
  when "1"
    name
  when "0"
    "#{name}_off".to_sym
  else
    raise "Unsupported value of '#{key}'"
  end
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/twitch/bot/irc_message.rb', line 28

def include?(key)
  @tags.key?(key)
end

#numeric_state(key, name, off_value:) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/twitch/bot/irc_message.rb', line 32

def numeric_state(key, name, off_value:)
  return unless tags.key?(key)

  case tags[key]
  when off_value
    "#{name}_off".to_sym
  else
    name.to_sym
  end
end