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

#initialize ⇒ void

Initializes a new SAX handler for parsing inventory item elements.

Sets up internal state to capture the cmd attribute and item name from the first element encountered during streaming XML parse.



177
178
179
180
181
182
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 177

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

Instance Attribute Details

#cmd ⇒ Object (readonly)

Returns the value of attribute cmd.



169
170
171
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 169

def cmd
  @cmd
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



169
170
171
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 169

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 value from a element.

Records the cmd attribute only if currently inside a element and the attribute has not yet been captured.

Parameters:

  • name (String) —

    the attribute name

  • value (String) —

    the attribute value



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

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 capture.

Exits capture mode after the first element closes, preventing later elements in the same parse from overwriting the captured cmd and name values.

Parameters:

  • name (String) —

    the element name



230
231
232
233
234
235
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 230

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.



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

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.

Marks the beginning of an XML element.

Enters capture mode when a element is encountered and the handler has not yet successfully closed one; later elements are ignored.

Parameters:

  • name (String) —

    the element name (e.g., "d", "component")



192
193
194
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 192

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.

Captures text content from inside a element.

Records the first text node encountered within a element as the item name; subsequent text nodes are ignored.

Parameters:

  • value (String) —

    the text content



217
218
219
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 217

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