Module: BBK::Utils::Xml

Defined in:
lib/bbk/utils/xml.rb,
sig/bbk/xml.rbs

Constant Summary collapse

MTOM_ID_FIRST_LETTERS =

Returns:

  • (Array[String])
%w[a b c d e f].freeze

Class Method Summary collapse

Class Method Details

.build_substituion_idString

Parameters:

  • id (string)

Returns:

  • (String)


5
# File 'sig/bbk/xml.rbs', line 5

def self.build_substituion_id: (string id) -> String

.build_substitution_id(id) ⇒ Object

Generate identifier to future substitution in XML body. Ex.: real attachment identifier when uploading to FTP



14
15
16
# File 'lib/bbk/utils/xml.rb', line 14

def self.build_substitution_id(id)
  "@{#{id}}"
end

.generate_mtom_attachment_idString

Generate uuid compatible with SOAP AttachmentContent identifier

Returns:

  • (String)


20
21
22
23
24
# File 'lib/bbk/utils/xml.rb', line 20

def self.generate_mtom_attachment_id
  id = SecureRandom.uuid
  id[0] = MTOM_ID_FIRST_LETTERS.sample
  id
end

.normalize_slug(name, href) ⇒ String

Normalize XML href to be predictible and constant in various cases

Parameters:

  • name (String)
  • href (String)

Returns:

  • (String)


28
29
30
31
32
33
34
35
36
# File 'lib/bbk/utils/xml.rb', line 28

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