Sha256: 3c7490f31423b73cc44919fc3423714d25b224a9cce4adf4a39fbe17f000a4a6

Contents?: true

Size: 1 KB

Versions: 18

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require 'securerandom'
require 'russian'

module BBK
  module Utils
    module Xml

      MTOM_ID_FIRST_LETTERS = %w[a b c d e f].freeze

      ##
      # Generate identifier to future substitution in XML body. Ex.: real attachment identifier when uploading to FTP
      def self.build_substitution_id(id)
        "@{#{id}}"
      end

      ##
      # Generate uuid compatible with SOAP AttachmentContent identifier
      def self.generate_mtom_attachment_id
        id = SecureRandom.uuid
        id[0] = MTOM_ID_FIRST_LETTERS.sample
        id
      end

      ##
      # Normalize XML href to be predictible and constant in various cases
      def self.normalize_slug(name, href)
        href_uri = URI.parse(href)
        href_slug = [href_uri.scheme, href_uri.host, *href_uri.path.split('/'), href_uri.query].select do |item|
          item.present?
        end.join('-').gsub(
          /[.&]/, '-'
        )
        Russian.translit "#{name}_#{href_slug}"
      end

    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
bbk-utils-1.1.1.275386 lib/bbk/utils/xml.rb
bbk-utils-1.1.0.274232 lib/bbk/utils/xml.rb
bbk-utils-1.1.0.273317 lib/bbk/utils/xml.rb
bbk-utils-1.1.0.181866 lib/bbk/utils/xml.rb
bbk-utils-1.1.0.149110 lib/bbk/utils/xml.rb
bbk-utils-1.0.1.147183 lib/bbk/utils/xml.rb
bbk-utils-1.0.1.136047 lib/bbk/utils/xml.rb
bbk-utils-1.0.1.133029 lib/bbk/utils/xml.rb
bbk-utils-1.0.1.102369 lib/bbk/utils/xml.rb
bbk-utils-1.0.1.100402 lib/bbk/utils/xml.rb
bbk-utils-1.0.1.100401 lib/bbk/utils/xml.rb
bbk-utils-1.0.1.97958 lib/bbk/utils/xml.rb
bbk-utils-1.0.1.97943 lib/bbk/utils/xml.rb
bbk-utils-1.0.1.93642 lib/bbk/utils/xml.rb
bbk-utils-1.0.1.89770 lib/bbk/utils/xml.rb
bbk-utils-1.0.1.84207 lib/bbk/utils/xml.rb
bbk-utils-1.0.1.72916 lib/bbk/utils/xml.rb
bbk-utils-1.0.1.72735 lib/bbk/utils/xml.rb