Class: AutomationObject::State::Base

Inherits:
Composite
  • Object
show all
Defined in:
lib/automation_object/state/_base.rb

Overview

Parent composite class

Instance Attribute Summary collapse

Attributes inherited from Composite

#children, #location, #name, #parent

Instance Method Summary collapse

Methods inherited from Composite

#add_has_many_relationships, #add_has_one_relationships, has_many, has_many_relationships, has_one, has_one_relationships

Methods included from Reflection

#add_alias, #add_attribute

Methods included from CompositeHook

#after_create_run, #before_create_run, included

Constructor Details

#initialize(driver, blue_prints, name = :top, parent = nil, location = 'top') ⇒ Base

Returns a new instance of Base

Parameters:



20
21
22
23
24
25
# File 'lib/automation_object/state/_base.rb', line 20

def initialize(driver, blue_prints, name = :top, parent = nil, location = 'top')
  self.driver = driver
  self.blue_prints = blue_prints

  super(name, parent, location)
end

Instance Attribute Details

#blue_printsAutomationObject::BluePrint::Composite::Base



13
14
15
# File 'lib/automation_object/state/_base.rb', line 13

def blue_prints
  @blue_prints
end

#driverAutomationObject::Driver::Driver



10
11
12
# File 'lib/automation_object/state/_base.rb', line 10

def driver
  @driver
end

Instance Method Details

#get_child(name, args) ⇒ Object

Overriding base get_child method

Parameters:

  • name (Symbol)

    name of child

  • args (Hash)

    args



30
31
32
33
34
35
36
# File 'lib/automation_object/state/_base.rb', line 30

def get_child(name, args)
  child_location = location + "[#{name}]"

  args.fetch(:interface).new(driver,
                             blue_prints.send(name),
                             name, self, child_location)
end

#get_children(name, args) ⇒ Object

Overriding base get_children method

Parameters:

  • name (Symbol)

    name of child

  • args (Hash)

    args



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/automation_object/state/_base.rb', line 42

def get_children(name, args)
  children_hash = {}

  blue_prints.send(name).each do |child_key, child_blue_prints|
    child_location = location + "[#{child_key}]"

    children_hash[child_key] = args.fetch(:interface).new(driver,
                                                          child_blue_prints,
                                                          child_key, self, child_location)
  end

  children_hash
end

#screenAutomationObject::State::Screen?

Recursive function to reach parent screen Can return nil if above a screen!



59
60
61
62
63
64
# File 'lib/automation_object/state/_base.rb', line 59

def screen
  return nil if is_a?(Top)

  # Should recursively call top until parent is nil
  is_a?(Screen) ? self : parent.screen
end

#topAutomationObject::State::Top

Recursive function to reach top



68
69
70
# File 'lib/automation_object/state/_base.rb', line 68

def top
  is_a?(Top) ? self : parent.top
end