Class: Lich::DragonRealms::Flags

Inherits:
Object
  • Object
show all
Defined in:
documented/dragonrealms/drinfomon/events.rb

Overview

Manages a set of flags and their associated matchers.

This class provides methods to add, reset, delete, and access flags.

See Also:

  • #add
  • #reset
  • #delete

Constant Summary collapse

@@flags =
{}
@@matchers =
{}

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Boolean?

Retrieves the value of a flag by its key.

Parameters:

  • key (String)

    the key of the flag to retrieve

Returns:

  • (Boolean, nil)

    the value of the flag or nil if not set



18
19
20
# File 'documented/dragonrealms/drinfomon/events.rb', line 18

def self.[](key)
  @@flags[key]
end

.[]=(key, value) ⇒ void

This method returns an undefined value.

Sets the value of a flag by its key.

Parameters:

  • key (String)

    the key of the flag to set

  • value (Boolean)

    the value to assign to the flag



26
27
28
# File 'documented/dragonrealms/drinfomon/events.rb', line 26

def self.[]=(key, value)
  @@flags[key] = value
end

.add(key, *matchers) ⇒ void

This method returns an undefined value.

Adds a new flag with the specified key and matchers.

Parameters:

  • key (String)

    the key for the new flag

  • matchers (Array<String, Regexp>)

    one or more matchers associated with the flag



34
35
36
37
# File 'documented/dragonrealms/drinfomon/events.rb', line 34

def self.add(key, *matchers)
  @@flags[key] = false
  @@matchers[key] = matchers.map { |item| item.is_a?(Regexp) ? item : /#{item}/i }
end

.delete(key) ⇒ void

This method returns an undefined value.

Deletes the specified flag and its associated matchers.

Parameters:

  • key (String)

    the key of the flag to delete



49
50
51
52
# File 'documented/dragonrealms/drinfomon/events.rb', line 49

def self.delete(key)
  @@matchers.delete key
  @@flags.delete key
end

.flagsHash<String, Boolean>

Returns a hash of all flags.

Returns:

  • (Hash<String, Boolean>)

    a hash containing all flags and their values



56
57
58
# File 'documented/dragonrealms/drinfomon/events.rb', line 56

def self.flags
  @@flags
end

.matchersHash<String, Array<Regexp>>

Returns a hash of all matchers associated with flags.

Returns:

  • (Hash<String, Array<Regexp>>)

    a hash containing all matchers for each flag



62
63
64
# File 'documented/dragonrealms/drinfomon/events.rb', line 62

def self.matchers
  @@matchers
end

.reset(key) ⇒ void

This method returns an undefined value.

Resets the specified flag to false.

Parameters:

  • key (String)

    the key of the flag to reset



42
43
44
# File 'documented/dragonrealms/drinfomon/events.rb', line 42

def self.reset(key)
  @@flags[key] = false
end