Class: Lich::DragonRealms::DRParser::InventoryItemSax
- Inherits:
-
Object
- Object
- Lich::DragonRealms::DRParser::InventoryItemSax
- Defined in:
- documented/dragonrealms/drinfomon/drparser.rb
Overview
Ox::Sax handler that extracts the cmd attribute and item name from the first
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#attr(name, value) ⇒ void
private
Called by the SAX parser when an attribute is encountered.
-
#end_element(name) ⇒ void
private
Called by the SAX parser when a closing tag is encountered.
-
#error(_message, _line, _column) ⇒ Object
Trailing prose after is not valid XML.
-
#initialize ⇒ InventoryItemSax
constructor
Initializes a SAX handler for parsing a single inventory item line.
-
#start_element(name) ⇒ void
private
Called by the SAX parser when an opening tag is encountered.
-
#text(value) ⇒ void
private
Called by the SAX parser when text content is encountered.
Constructor Details
#initialize ⇒ InventoryItemSax
Initializes a SAX handler for parsing a single inventory item line.
Sets up internal state to capture the cmd attribute and item name from the first
242 243 244 245 246 247 |
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 242 def initialize @in_d = false @done = false @cmd = nil @name = nil end |
Instance Attribute Details
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
234 235 236 |
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 234 def cmd @cmd end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
234 235 236 |
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 234 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.
Called by the SAX parser when an attribute is encountered.
Captures the cmd attribute value from the active
270 271 272 |
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 270 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.
Called by the SAX parser when a closing tag is encountered.
Marks the
294 295 296 297 298 299 |
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 294 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.
303 |
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 303 def error(, _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.
Called by the SAX parser when an opening tag is encountered.
Marks the cmd attribute and text content can be captured.
Only the first
257 258 259 |
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 257 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.
Called by the SAX parser when text content is encountered.
Captures the item name from inside the
282 283 284 |
# File 'documented/dragonrealms/drinfomon/drparser.rb', line 282 def text(value) @name = value if @in_d && @name.nil? end |