class Logasm::Preprocessors::Strategies::Prune

Public Class Methods

new(trie) click to toggle source
# File lib/logasm/preprocessors/strategies/prune.rb, line 5
def initialize(trie)
  @trie = trie
end

Public Instance Methods

process(data, pointer = '') click to toggle source
# File lib/logasm/preprocessors/strategies/prune.rb, line 9
def process(data, pointer = '')
  return nil unless @trie.include?(pointer)

  case data
  when Hash
    process_hash(data, pointer)

  when Array
    process_array(data, pointer)

  else
    data
  end
end

Private Instance Methods

process_array(data, parent_pointer) click to toggle source
# File lib/logasm/preprocessors/strategies/prune.rb, line 34
def process_array(data, parent_pointer)
  data.each_with_index.each_with_object([]) do |(value, index), result|
    path = "#{parent_pointer}/#{index}"

    result << process(value, path) if @trie.include?(path)
  end
end
process_hash(data, parent_pointer) click to toggle source
# File lib/logasm/preprocessors/strategies/prune.rb, line 26
def process_hash(data, parent_pointer)
  data.each_with_object({}) do |(key, value), result|
    path = "#{parent_pointer}/#{key}"

    result[key] = process(value, path) if @trie.include?(path)
  end
end