module HQMF2::Utilities
Module containing parser helper functions
Public Class Methods
attr_val(node, xpath)
click to toggle source
Utility function to handle optional attributes @param xpath an XPath that identifies an XML attribute @return the value of the attribute or nil if the attribute is missing
# File lib/hqmf-parser/2.0/utilities.rb, line 16 def self.attr_val(node, xpath) attr = node.at_xpath(xpath, HQMF2::Document::NAMESPACES) return attr.value if attr end
Public Instance Methods
attr_val(xpath)
click to toggle source
Utility function to handle optional attributes @param xpath an XPath that identifies an XML attribute @return the value of the attribute or nil if the attribute is missing
# File lib/hqmf-parser/2.0/utilities.rb, line 9 def attr_val(xpath) Utilities.attr_val(@entry, xpath) end
strip_tokens(value)
click to toggle source
General helper for stripping '-' and ',' into '_' for processable ids
# File lib/hqmf-parser/2.0/utilities.rb, line 26 def strip_tokens(value) return nil if value.nil? stripped = value.gsub(/[^0-9a-z]/i, '_') # Prefix digits with 'prefix_' to prevent JS syntax errors stripped.gsub(/^[0-9]/, "prefix_#{value[0]}") end
to_xml()
click to toggle source
# File lib/hqmf-parser/2.0/utilities.rb, line 21 def to_xml @entry.to_xml end