Sha256: f25ec6167a8704a9e8a9d537b413d8a4c3078cbfcdc17baa045e59e212b5a3aa

Contents?: true

Size: 1.25 KB

Versions: 36

Compression:

Stored size: 1.25 KB

Contents

module HQMF2
  # Module containing parser helper functions
  module Utilities
    include HQMF::Conversion::Utilities

    # 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
    def attr_val(xpath)
      Utilities.attr_val(@entry, xpath)
    end

    # 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
    def self.attr_val(node, xpath)
      attr = node.at_xpath(xpath, HQMF2::Document::NAMESPACES)
      return attr.value if attr
    end

    def to_xml
      @entry.to_xml
    end

    # General helper for stripping '-' and ',' into '_' for processable ids
    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

    # Class that generates incremental ids
    class IdGenerator
      def initialize
        @current_id = 0
      end

      def next_id
        @current_id += 1
        @current_id
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
cqm-parsers-4.1.1.0 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-4.1.0.2 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-4.1.0.1 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-4.1.0.0 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-4.0.0.1 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-3.2.0.2 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-4.0.0.0 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-3.2.0.1 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-3.2.0.0 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-3.1.1.0 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-3.1.0.0 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-3.0.0.0 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-2.0.1 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-0.2.4 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-2.0.0 lib/hqmf-parser/2.0/utilities.rb
health-data-standards-4.3.5 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-0.2.3 lib/hqmf-parser/2.0/utilities.rb
health-data-standards-4.3.4 lib/hqmf-parser/2.0/utilities.rb
cqm-parsers-0.2.2 lib/hqmf-parser/2.0/utilities.rb
health-data-standards-4.3.3 lib/hqmf-parser/2.0/utilities.rb