class Arboretum::Scandent::LocatorPath
Attributes
steps[RW]
Public Class Methods
new(steps=[])
click to toggle source
# File lib/arboretum/scandent.rb, line 109 def initialize(steps=[]) # Make sure that the locators stems from the root or current context element if steps.first.element_ref.nil? steps.first.action = :ACTION_CHILD if steps.first.action == :ACTION_SELF implied_step = [ [:T_DOT, '.', :STATE_ROOT_PATH], ] steps.unshift(Parser.parse_step_tokens(implied_step, :PATH_LOCATOR)) end # Make sure there are no misplaced :ELEMENT_SELF references steps.each {|step| raise InvalidExpressionException.new if step.element_ref == :ELEMENT_SELF and !step.eql?(steps.first)} @steps = steps end
Public Instance Methods
locate(element) { |match| ... }
click to toggle source
# File lib/arboretum/scandent.rb, line 124 def locate(element) matches = [element] next_round = [] @steps.each do |step| next_round = [] matches.each do |matched_element| next_round += step.match(matched_element) end return next_round if next_round.empty? matches = next_round end matches.each {|match| yield match if block_given?} return matches end
steps_valid_on?(steps, candidate)
click to toggle source
# File lib/arboretum/scandent.rb, line 143 def steps_valid_on?(steps, candidate) return true if steps.empty? steps.first.match(candidate) do |element| return true if steps_valid_on?(steps[1..-1], element) end return false end
to_s()
click to toggle source
# File lib/arboretum/scandent.rb, line 151 def to_s path_string = '' @steps.each{|step| path_string << step.to_s} path_string end
valid_on?(candidate)
click to toggle source
# File lib/arboretum/scandent.rb, line 139 def valid_on?(candidate) steps_valid_on?(@steps, candidate) end