class Kitchen::Ancestor
A wrapper for an element representing an ancestor (up the DOM tree) of another element; keeps track of the number of descendants it has of a particular type
Attributes
The ancestor element @return [ElementBase] the ancestor element
The type, e.g. :page
, :term
@return [Symbol] the type
Public Class Methods
Create a new Ancestor
@param element [ElementBase] the ancestor element
# File lib/kitchen/ancestor.rb, line 23 def initialize(element) @element = element @type = element.short_type @descendant_counts = {} end
Public Instance Methods
Makes a new Ancestor
around the same element, with new counts
# File lib/kitchen/ancestor.rb, line 61 def clone # @todo Delete later if not used Ancestor.new(element) end
Decreases the descendant count for the given type by some amount
@param descendant_type [String, Symbol] the descendent's type @param by [Integer] the amount by which to decrement @raise [RangeError] if descendant count is a negative number
# File lib/kitchen/ancestor.rb, line 43 def decrement_descendant_count(descendant_type, by: 1) raise(RangeError, 'An element cannot have negative descendants') \ if (get_descendant_count(descendant_type) - by).negative? @descendant_counts[descendant_type.to_sym] = get_descendant_count(descendant_type) - by end
Returns the descendant count for the given type
@param descendant_type [String, Symbol] the descendent's type @return [Integer] the count
# File lib/kitchen/ancestor.rb, line 55 def get_descendant_count(descendant_type) @descendant_counts[descendant_type.to_sym] || 0 end
Adds 1 to the descendant count for the given type
@param descendant_type [String, Symbol] the descendent's type
# File lib/kitchen/ancestor.rb, line 33 def increment_descendant_count(descendant_type) @descendant_counts[descendant_type.to_sym] = get_descendant_count(descendant_type) + 1 end