Module: Uia::Finder

Included in:
Uia, Element
Defined in:
lib/uia/finder.rb

Instance Method Summary collapse

Instance Method Details

#find_child(parent, locator) ⇒ Object

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/uia/finder.rb', line 31

def find_child(parent, locator)
  scope = (locator.delete(:scope) || :descendants).to_s.capitalize

  valid_locators = [:title, :handle, :id, :name, :value, :control_type, :pattern, :scope]
  raise BadChildLocator, locator unless (locator.keys - valid_locators).empty?

  case
    when locator[:title]
      find_by_title locator[:title], parent.handle
    when locator[:handle]
      find_by_handle locator[:handle]
    else
      conditions = locator.collect {|k, v|  Library.send("#{k}_condition", v) }
      Library.find_first parent, scope, *conditions
  end
end

#find_children(parent, locator) ⇒ Object

Raises:



48
49
50
51
52
53
54
55
56
# File 'lib/uia/finder.rb', line 48

def find_children(parent, locator)
  scope = (locator.delete(:scope) || :descendants).to_s.capitalize

  valid_locators = [:id, :name, :value, :control_type, :pattern, :scope]
  raise BadChildLocator, locator unless (locator.keys - valid_locators).empty?

  conditions = locator.collect {|k, v|  Library.send("#{k}_condition", v) }
  Library.find_all parent, scope, *conditions
end

#find_from_root(locator) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/uia/finder.rb', line 12

def find_from_root(locator)
  case
    when locator[:id]
      find_by_id locator[:id]
    when locator[:name], locator[:value]
      find_by_name locator[:name] || locator[:value]
    when locator[:pid]
      find_by_pid locator[:pid]
    when locator[:runtime_id]
      find_by_runtime_id locator[:runtime_id]
    when locator[:handle]
      find_by_handle locator[:handle]
    when locator[:title]
      find_by_title locator[:title]
    else
      raise BadLocator, locator
  end
end