Class: PageMagic::Watcher

Inherits:
Object show all
Defined in:
lib/page_magic/watcher.rb

Overview

class WatchedElementDefinition - Contains the specification the for checking if an subject has changed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, context:, &block) ⇒ Watcher

Returns a new instance of Watcher.

Examples:

Watcher.new(:url) do
  session.url
end

Parameters:

  • name (Symbol)

    the of the subject being checked



13
14
15
16
17
# File 'lib/page_magic/watcher.rb', line 13

def initialize(name, context:, &block)
  @name = name
  @context = context
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



6
7
8
# File 'lib/page_magic/watcher.rb', line 6

def block
  @block
end

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'lib/page_magic/watcher.rb', line 6

def context
  @context
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/page_magic/watcher.rb', line 6

def name
  @name
end

#observed_valueObject (readonly)

Returns the value of attribute observed_value.



6
7
8
# File 'lib/page_magic/watcher.rb', line 6

def observed_value
  @observed_value
end

Instance Method Details

#==(other) ⇒ Boolen

Returns true of the candiate is equal ot this one.

Parameters:

  • other (Object)

    candidate for equality check

Returns:

  • (Boolen)

    true of the candiate is equal ot this one.



30
31
32
33
34
# File 'lib/page_magic/watcher.rb', line 30

def ==(other)
  other.is_a?(Watcher) &&
    name == other.name &&
    block == other.block
end

#checkPageMagic::Watcher

check current value of watched element. The result of the check can be accessed by calling #last if a block was specified to the constructor then this will be executed.

Returns:



23
24
25
26
# File 'lib/page_magic/watcher.rb', line 23

def check
  @observed_value = context.instance_eval(&block)
  self
end