Sha256: c7cb360f56e1828342e7ac76935b6c2978d872408c30dd21320fe916a03e5b6c

Contents?: true

Size: 619 Bytes

Versions: 43

Compression:

Stored size: 619 Bytes

Contents

module Relaton
  module ElementFinder
    attr_reader :document

    def find_text(xpath, element = nil)
      find(xpath, element)&.text
    end

    def find(xpath, element = nil)
      (element || document).at(apply_namespace(xpath))
    end

    def find_xpath(xpath, element = nil)
      element&.xpath(apply_namespace(xpath))
    end

    def apply_namespace(xpath)
      xpath
        .gsub(%r{/([a-zA-Z])}, "/xmlns:\\1")
        .gsub(%r{::([a-zA-Z])}, "::xmlns:\\1")
        .gsub(%r{\[([a-zA-Z][a-z0-9A-Z@/]* ?=)}, "[xmlns:\\1")
        .gsub(%r{\[([a-zA-Z][a-z0-9A-Z@/]*\])}, "[xmlns:\\1")
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
relaton-cli-1.19.3 lib/relaton/element_finder.rb
relaton-cli-1.19.2 lib/relaton/element_finder.rb
relaton-cli-1.19.1 lib/relaton/element_finder.rb
relaton-cli-1.19.0 lib/relaton/element_finder.rb
relaton-cli-1.18.1 lib/relaton/element_finder.rb
relaton-cli-1.18.0 lib/relaton/element_finder.rb
relaton-cli-1.17.2 lib/relaton/element_finder.rb
relaton-cli-1.17.1 lib/relaton/element_finder.rb
relaton-cli-1.17.0 lib/relaton/element_finder.rb
relaton-cli-1.16.1 lib/relaton/element_finder.rb
relaton-cli-1.16.0 lib/relaton/element_finder.rb
relaton-cli-1.15.6 lib/relaton/element_finder.rb
relaton-cli-1.15.5 lib/relaton/element_finder.rb
relaton-cli-1.15.4 lib/relaton/element_finder.rb
relaton-cli-1.15.3 lib/relaton/element_finder.rb
relaton-cli-1.15.2 lib/relaton/element_finder.rb
relaton-cli-1.15.1 lib/relaton/element_finder.rb
relaton-cli-1.15.0 lib/relaton/element_finder.rb
relaton-cli-1.14.1 lib/relaton/element_finder.rb
relaton-cli-1.14.0 lib/relaton/element_finder.rb