class PathManipulator
Attributes
node_value_extractor[R]
Public Class Methods
new(node_value_extractor)
click to toggle source
# File lib/src/extractor.rb, line 141 def initialize(node_value_extractor) @node_value_extractor = node_value_extractor end
Public Instance Methods
replace_link(original_path, link_path)
click to toggle source
# File lib/src/extractor.rb, line 145 def replace_link(original_path, link_path) return original_path if link_path.blank? link_value = node_value_extractor.tag_values(link_path, nil) original_path.gsub "<link>", link_value end
uniq_paths(paths, uniq_by_path)
click to toggle source
# File lib/src/extractor.rb, line 153 def uniq_paths(paths, uniq_by_path) paths .map { |path| { path: path, value: tag_value(path, uniq_by_path) } } .then { |paths_values| remove_duplicated_paths(paths_values) } .map { |path_value| path_value[:path] } end
Private Instance Methods
first_path_value_index(paths_values, current_path)
click to toggle source
# File lib/src/extractor.rb, line 174 def first_path_value_index(paths_values, current_path) paths_values.find_index { |path_value| path_value[:value] == current_path[:value] } end
remove_duplicated_paths(paths_values)
click to toggle source
# File lib/src/extractor.rb, line 168 def remove_duplicated_paths(paths_values) paths_values.delete_if.with_index do |path_value, index| index != first_path_value_index(paths_values, path_value) end end
tag_value(path, uniq_by_path)
click to toggle source
# File lib/src/extractor.rb, line 164 def tag_value(path, uniq_by_path) node_value_extractor.tag_values([path, uniq_by_path].join("/"), "") end