class Hypermicrodata::FormItem

Attributes

submit_buttons[R]

Public Class Methods

new(top_node, page_url) click to toggle source
Calls superclass method Hypermicrodata::Item::new
# File lib/hypermicrodata/item.rb, line 114
def initialize(top_node, page_url)
  form = Mechanize::Form.new(top_node)
  @submit_buttons = form.submits.map do |button|
    SubmitButton.new(button, form)
  end
  super
end

Private Instance Methods

add_itemprop(element) click to toggle source
Calls superclass method Hypermicrodata::Item#add_itemprop
# File lib/hypermicrodata/item.rb, line 137
def add_itemprop(element)
  return super unless submit_button_include?(element)
  property = @submit_buttons.find {|b| b.node == element }
  if property.names.empty? && property.rels.empty?
    href = property.value.to_s.strip
    unless href.empty? || href == '#' # href which doesn't work as link is ignored
      (@links[element.name] ||= []) << property
    end
  else
    property.names.each { |name| (@properties[name] ||= []) << property }
    property.rels.each { |rel| (@links[rel] ||= []) << property }
  end
end
extract_itemtype() click to toggle source
Calls superclass method Hypermicrodata::Item#extract_itemtype
# File lib/hypermicrodata/item.rb, line 124
def extract_itemtype
  super || ['http://schema.org/Action']
end
parse_element(element) click to toggle source

TODO: Make it DRY

# File lib/hypermicrodata/item.rb, line 129
def parse_element(element)
  itemscope = element.attribute('itemscope')
  itemprop = element.attribute('itemprop')
  internal_elements = extract_elements(element)
  add_itemprop(element) if itemprop || ItempropParser::LINK_ELEMENTS.include?(element.name) || submit_button_include?(element)
  parse_elements(internal_elements) if internal_elements && !itemscope
end
submit_button_include?(element) click to toggle source
# File lib/hypermicrodata/item.rb, line 151
def submit_button_include?(element)
  @submit_buttons.any? {|b| b.node == element }
end