Class: Lich::DragonRealms::Flags

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

Overview

Manages flags and matchers for the DragonRealms module This class provides methods to add, reset, delete, and access flags and their associated matchers.

Examples:

Adding a flag

Flags.add(:example_flag, /pattern/, "string")

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Boolean?

Retrieves the value of a flag by its key

Examples:

Retrieving a flag

value = Flags[:example_flag]

Parameters:

  • key (Symbol)

    The key of the flag to retrieve

Returns:

  • (Boolean, nil)

    The value of the flag or nil if not found



16
17
18
# File 'documented/dragonrealms/drinfomon/events.rb', line 16

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

.[]=(key, value) ⇒ Boolean

Sets the value of a flag by its key

Examples:

Setting a flag

Flags[:example_flag] = true

Parameters:

  • key (Symbol)

    The key of the flag to set

  • value (Boolean)

    The value to assign to the flag

Returns:

  • (Boolean)

    The value that was set



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 associated matchers

Examples:

Adding a flag with matchers

Flags.add(:example_flag, /pattern/, "string")

Parameters:

  • key (Symbol)

    The key for the new flag

  • matchers (Array<Regexp, String>)

    One or more matchers to associate with the flag



36
37
38
39
# File 'documented/dragonrealms/drinfomon/events.rb', line 36

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 a flag and its associated matchers

Examples:

Deleting a flag

Flags.delete(:example_flag)

Parameters:

  • key (Symbol)

    The key of the flag to delete



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

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

.flagsHash<Symbol, Boolean>

Returns all flags

Examples:

Accessing all flags

all_flags = Flags.flags

Returns:

  • (Hash<Symbol, Boolean>)

    A hash of all flags and their values



64
65
66
# File 'documented/dragonrealms/drinfomon/events.rb', line 64

def self.flags
  @@flags
end

.matchersHash<Symbol, Array<Regexp>] A hash of all matchers for each flag

Returns all matchers associated with flags

Examples:

Accessing all matchers

all_matchers = Flags.matchers

Returns:

  • (Hash<Symbol, Array<Regexp>] A hash of all matchers for each flag)

    Hash<Symbol, Array<Regexp>] A hash of all matchers for each flag



72
73
74
# File 'documented/dragonrealms/drinfomon/events.rb', line 72

def self.matchers
  @@matchers
end

.reset(key) ⇒ void

This method returns an undefined value.

Resets the value of a flag to false

Examples:

Resetting a flag

Flags.reset(:example_flag)

Parameters:

  • key (Symbol)

    The key of the flag to reset



46
47
48
# File 'documented/dragonrealms/drinfomon/events.rb', line 46

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