class Glob::Query
Attributes
matchers[R]
Public Class Methods
new(target)
click to toggle source
# File lib/glob/query.rb, line 7 def initialize(target) @target = target @matchers = [] end
Public Instance Methods
<<(path)
click to toggle source
# File lib/glob/query.rb, line 12 def <<(path) matchers << Matcher.new(path) end
Also aliased as: filter
paths()
click to toggle source
# File lib/glob/query.rb, line 28 def paths matches = map.map do |path| results = matchers.select {|matcher| matcher.match?(path) } [path, results] end matches .select {|(_, results)| results.compact.last&.include? } .map {|(path)| path } .sort end
to_h()
click to toggle source
# File lib/glob/query.rb, line 17 def to_h symbolized_target = SymbolizeKeys.call(@target) paths.each_with_object({}) do |path, buffer| segments = path.split(".").map(&:to_sym) value = symbolized_target.dig(*segments) set_path_value(segments, buffer, value) end end
Also aliased as: to_hash
Private Instance Methods
map()
click to toggle source
# File lib/glob/query.rb, line 40 def map @map ||= Map.call(@target) end
set_path_value(segments, target, value)
click to toggle source
# File lib/glob/query.rb, line 44 def set_path_value(segments, target, value) while (segment = segments.shift) if segments.empty? target[segment] = value else target[segment] ||= {} target = target[segment] end end end