Class: Locatine::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/locatine/scope.rb

Overview

Scope is the class representing group of elements

Locatine has scopes

Instance Method Summary collapse

Constructor Details

#initialize(scope, search) ⇒ Scope

Returns a new instance of Scope.



7
8
9
10
# File 'lib/locatine/scope.rb', line 7

def initialize(scope, search)
  @search = search
  @scope = scope
end

Instance Method Details

#all(vars = {}) ⇒ Object

Getting all the elements of the scope at once

Params:

vars hash of vars used for dynamic attributes. Same as in :find



30
31
32
# File 'lib/locatine/scope.rb', line 30

def all(vars = {})
  find_all(vars)
end

#check(vars = {}) ⇒ Object

Checking all the elements of the scope at once. Will fail if something was lost

Params:

vars hash of vars used for dynamic attributes. Same as in :find



41
42
43
44
45
46
47
48
49
50
# File 'lib/locatine/scope.rb', line 41

def check(vars = {})
  success = []
  result = find_all(vars, true)
  result.each_pair do |name, hash|
    success.push name if hash[:elements].empty?
  end
  raise "Check of #{@scope} failed! Lost: #{success}" unless success.empty?

  result
end

#define(vars = {}) ⇒ Object

Way to define locatine a bunch elements at once. Elements will be taken from user selection one by one and saved in scope.

Params:

vars hash of vars used for dynamic attributes. Same as in :find



19
20
21
22
# File 'lib/locatine/scope.rb', line 19

def define(vars = {})
  find_all(vars, false, true) if data.to_h != {}
  new_define(vars)
end