class PathBuilder

Public Instance Methods

build() click to toggle source
# File lib/src/extractor.rb, line 6
def build
  paths = relative_path.split("/").then do |paths|
    if parent.present?
      navigate_to_parent(parent, paths)
    else
      paths
    end
  end

  paths << tag unless tag.is_a? Array
  full_path = paths.flatten.compact.join("/")
  "//#{full_path}"
end

Private Instance Methods

matching_tags?(item, tag) click to toggle source
# File lib/src/extractor.rb, line 39
def matching_tags?(item, tag)
  item.gsub(/\[\d\]/, "") == tag
end
navigate_to_parent(parent_tag, paths) click to toggle source
path_index(tag, paths) click to toggle source
# File lib/src/extractor.rb, line 32
def path_index(tag, paths)
  paths.each_with_index do |path, index|
    return index if matching_tags?(path, tag)
  end
  0
end
relative_path() click to toggle source
# File lib/src/extractor.rb, line 22
def relative_path
  base.start_with?("//") ? base[2..-1] : base
end