shard-spectator/src/spectator/tag_node_filter.cr

19 lines
529 B
Crystal
Raw Normal View History

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)
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) }
end
end
end