Class: Lich::DragonRealms::DRParser::InventoryItemSax

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

Overview

Ox::Sax handler that extracts the cmd attribute and item name from the first element of an inventory line, e.g. a small pouch. Streaming means the element is captured before any trailing prose, which is not well-formed XML; the resulting parse error is swallowed by #error.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializevoid

Initializes the SAX handler with parsing state ready to extract the cmd attribute and item name from the first element in an inventory line.



154
155
156
157
158
159
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 154

def initialize
  @in_d = false
  @done = false
  @cmd = nil
  @name = nil
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd.



148
149
150
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 148

def cmd
  @cmd
end

#nameObject (readonly)

Returns the value of attribute name.



148
149
150
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 148

def name
  @name
end

Instance Method Details

#attr(name, value) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Captures the cmd attribute from an open element.

Parameters:

  • name (String)

    the attribute name (e.g., "cmd")

  • value (String)

    the attribute value (e.g., "get #12345 in #67890")



176
177
178
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 176

def attr(name, value)
  @cmd = value if @in_d && name == "cmd"
end

#end_element(name) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Marks the end of a element and stops parsing after the first one. Subsequent elements are ignored; only the leading item is extracted.

Parameters:

  • name (String)

    the XML element name



196
197
198
199
200
201
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 196

def end_element(name)
  return unless @in_d && name == "d"

  @in_d = false
  @done = true # ignore any later <d> elements; we only want the leading item
end

#error(_message, _line, _column) ⇒ Object

Trailing prose after is not valid XML. We have already captured the element by the time Ox reports it, so the error is intentionally ignored.



205
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 205

def error(_message, _line, _column); end

#start_element(name) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Records when a element begins, marking it for attribute and text capture.

Parameters:

  • name (String)

    the XML element name (e.g., "d", "output")



166
167
168
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 166

def start_element(name)
  @in_d = true if name == "d" && !@done
end

#text(value) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Records the item name from the text content of a element. Only captures the first text node; subsequent text is ignored.

Parameters:

  • value (String)

    the text content of the element



186
187
188
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 186

def text(value)
  @name = value if @in_d && @name.nil?
end