Class: Celerity::MethodGenerator

Experimental - generate a method definition for accessing elements on the current page.

Usage:

   MethodGenerator.new(browser, opts).parse

Constants

BUGGY_ELEMENTS
%w[radio checkbox].map { |e| e.to_sym }
ELEMENTS
%w[text_field select_list radio checkbox button].map { |e| e.to_sym }

Constructor Summary

public initialize(ie, opts = )
[View source]


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/celerity/extra/method_generator.rb', line 33

def initialize(ie, opts = ;{})
  @ie      = ie
  @opts    = opts
  @browser = @opts[:browser] || '@ie'

  @docs = "  # Fills in the page at #{@ie.url}\n  #\n"
  @docs << "  # Parameters:\n  #\n"
  @doc_elements = []

  @method = "  def #{@opts[:method_name] || 'generated_method'}(opts = {})\n\n"
end

Public Visibility

Public Instance Method Summary

#parse

Public Instance Method Details

parse

public parse
[View source]


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/celerity/extra/method_generator.rb', line 45

def parse
  ELEMENTS.each do |elem|
    @method << "    # buggy!\n" if BUGGY_ELEMENTS.include?(elem)
    add_elements(elem)
  end
  add_elements(:link) if @opts[:include_links]
  @method << "  end\n\n"

  # fix docs
  max = @doc_elements.map { |symbol, _| symbol.to_s.size }.max
  @doc_elements.each do |sym, desc|
    @docs << "  #  #{sym.to_s.ljust(max)} => #{desc}\n"
  end
  @docs << "  #\n"*2
  @docs + @method
end