Class: PageObjectify::DOM

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/page-objectify/dom.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(html) ⇒ DOM

Returns a new instance of DOM.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/page-objectify/dom.rb', line 11

def initialize(html)
  @html = html
  @doc = Nokogiri::HTML(@html)
  @accessors = []
  @tags_to_accessors = {}
  @input_types_to_accessors = {}
  @types = i(text password checkbox button image reset submit radio hidden file)
  @ignored_tags = i(meta style body script thead tbody) # that could possibly have an HTML id

  generate_mapping
end

Instance Attribute Details

#input_types_to_accessorsObject (readonly)

Returns the value of attribute input_types_to_accessors.



9
10
11
# File 'lib/page-objectify/dom.rb', line 9

def input_types_to_accessors
  @input_types_to_accessors
end

#tags_to_accessorsObject (readonly)

Returns the value of attribute tags_to_accessors.



9
10
11
# File 'lib/page-objectify/dom.rb', line 9

def tags_to_accessors
  @tags_to_accessors
end

Instance Method Details

#to_accessorsObject



23
24
25
26
27
28
29
30
31
# File 'lib/page-objectify/dom.rb', line 23

def to_accessors
  # Grab only nodes with non-empty HTML id
  @doc.xpath("//*[@id!='']").each do |node|
    accessor = accessor_for(node)
    @accessors << { accessor: accessor, id: node.attributes["id"].to_s } if accessor
  end
  logger.info "DOM nodes convertable to PageObject::Accessors: #{@accessors.count}"
  @accessors
end