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.13.0 lib/relaton/element_finder.rb
relaton-cli-1.12.1 lib/relaton/element_finder.rb
relaton-cli-1.12.0 lib/relaton/element_finder.rb
relaton-cli-1.11.0 lib/relaton/element_finder.rb
relaton-cli-1.10.2 lib/relaton/element_finder.rb
relaton-cli-1.10.1 lib/relaton/element_finder.rb
relaton-cli-1.10.0 lib/relaton/element_finder.rb
relaton-cli-1.9.5 lib/relaton/element_finder.rb
relaton-cli-1.9.4 lib/relaton/element_finder.rb
relaton-cli-1.9.3 lib/relaton/element_finder.rb
relaton-cli-1.9.2 lib/relaton/element_finder.rb
relaton-cli-1.9.1 lib/relaton/element_finder.rb
relaton-cli-1.9.0 lib/relaton/element_finder.rb
relaton-cli-1.8.2 lib/relaton/element_finder.rb
relaton-cli-1.8.0 lib/relaton/element_finder.rb
relaton-cli-1.7.4 lib/relaton/element_finder.rb
relaton-cli-1.7.3 lib/relaton/element_finder.rb
relaton-cli-1.7.pre3 lib/relaton/element_finder.rb
relaton-cli-1.7.2 lib/relaton/element_finder.rb
relaton-cli-1.7.1 lib/relaton/element_finder.rb