Module: HQMF2::Utilities

Overview

Module containing parser helper functions

Defined Under Namespace

Classes: IdGenerator

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HQMF::Conversion::Utilities

#build_hash, #check_equality, #json_array, #openstruct_to_json

Class Method Details

.attr_val(node, xpath) ⇒ Object

Utility function to handle optional attributes

Parameters:

  • xpath

    an XPath that identifies an XML attribute

Returns:

  • the value of the attribute or nil if the attribute is missing



16
17
18
19
# 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

Instance Method Details

#attr_val(xpath) ⇒ Object

Utility function to handle optional attributes

Parameters:

  • xpath

    an XPath that identifies an XML attribute

Returns:

  • the value of the attribute or nil if the attribute is missing



9
10
11
# File 'lib/hqmf-parser/2.0/utilities.rb', line 9

def attr_val(xpath)
  Utilities.attr_val(@entry, xpath)
end

#strip_tokens(value) ⇒ Object

General helper for stripping ‘-’ and ‘,’ into ‘_’ for processable ids



26
27
28
29
30
31
# 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_xmlObject



21
22
23
# File 'lib/hqmf-parser/2.0/utilities.rb', line 21

def to_xml
  @entry.to_xml
end