2021-08-18 02:52:06 +00:00
|
|
|
require "./node_filter"
|
|
|
|
|
|
|
|
module Spectator
|
|
|
|
# Filter that matches nodes with a given tag.
|
|
|
|
class TagNodeFilter < NodeFilter
|
|
|
|
# Creates the filter.
|
|
|
|
# The *tag* indicates which tag the node must have in its metadata.
|
2021-08-18 03:34:26 +00:00
|
|
|
def initialize(@tag : String, @value : String? = nil)
|
2021-08-18 02:52:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Checks whether the node satisfies the filter.
|
|
|
|
def includes?(node) : Bool
|
2022-11-30 06:22:42 +00:00
|
|
|
return false unless metadata = node.metadata
|
|
|
|
|
|
|
|
metadata.any? { |key, value| key.to_s == @tag && (!@value || value == @value) }
|
2021-08-18 02:52:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|