Class: WebViewer::ElementValueReader

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

Overview

ElementValueReader acts on a Selenium::WebDriver::Element by fetching its value, clicking on it, reading its text, etc.

Instance Method Summary collapse

Constructor Details

#initialize(element_reader, output_type) ⇒ ElementValueReader

Returns a new instance of ElementValueReader.



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

def initialize(element_reader, output_type)
  @element_reader = element_reader
  @output_type = output_type
end

Instance Method Details

#[](*args) ⇒ Object



21
22
23
# File 'lib/element_value_reader.rb', line 21

def [](*args)
  element_value(*args)
end

#[]=(*arguments) ⇒ Object



25
26
27
28
29
# File 'lib/element_value_reader.rb', line 25

def []=(*arguments)
  value_to_assign = arguments.pop
  element = @element_reader.get(*arguments)
  ElementValueWriter.new(element, @output_type).value = value_to_assign
end

#element_as_viewer(*arguments) ⇒ Object



41
42
43
44
45
# File 'lib/element_value_reader.rb', line 41

def element_as_viewer(*arguments)
  viewer = @output_type.new
  viewer.base_element = lambda { @element_reader.get(*arguments) }
  viewer
end

#element_value(*arguments) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/element_value_reader.rb', line 31

def element_value(*arguments)
  if (Class === @output_type)
    element_as_viewer(*arguments)
  elsif [:auto, :link, :select_by_text, :select_by_value].include? @output_type
    raise "not yet implemented"
  else
    @element_reader.get(*arguments).send(@output_type)
  end
end

#getObject

return either self or element_value depending on whether selector needs parameters



13
14
15
16
17
18
19
# File 'lib/element_value_reader.rb', line 13

def get
  if @element_reader.requires_parameters?
    self
  else
    element_value
  end
end