Class: Hypermicrodata::ItempropParser

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

Overview

Class that parses itemprop elements

Constant Summary collapse

NON_TEXTCONTENT_ELEMENTS =
{
  'a' => 'href',        'area' => 'href',
  'audio' => 'src',     'embed' => 'src',
  'iframe' => 'src',    'img' => 'src',
  'link' => 'href',     'meta' => 'content',
  'object' => 'data',   'source' => 'src',
  'time' => 'datetime', 'track' => 'src',
  'video' => 'src'
}
['a', 'area', 'audio', 'embed', 'iframe',
'img', 'link', 'source', 'track', 'video']
URL_ATTRIBUTES =
['data', 'href', 'src']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element, page_url = nil) ⇒ ItempropParser

Create a new Itemprop object

element

The itemprop element to be parsed

page_url

The url of the page, including filename, used to form absolute urls



28
29
30
31
32
33
34
35
# File 'lib/hypermicrodata/itemprop_parser.rb', line 28

def initialize(element, page_url=nil)
  @element, @page_url = element, page_url
  if link?
    @property = Link.new(extract_property, extract_property_names, extract_rel_names)
  else
    @property = Property.new(extract_property, extract_property_names, extract_rel_names)
  end
end

Instance Attribute Details

#propertyObject (readonly)

A Hash representing the properties. Hash is of the form name’ => ‘value’



22
23
24
# File 'lib/hypermicrodata/itemprop_parser.rb', line 22

def property
  @property
end

Class Method Details

.parse(element, page_url = nil) ⇒ Object

Parse the element and return a hash representing the properties. Hash is of the form name’ => ‘value’

element

The itemprop element to be parsed

page_url

The url of the page, including filename, used to form absolute urls



42
43
44
# File 'lib/hypermicrodata/itemprop_parser.rb', line 42

def self.parse(element, page_url=nil)
  self.new(element, page_url).property
end

Instance Method Details

#link?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/hypermicrodata/itemprop_parser.rb', line 46

def link?
  LINK_ELEMENTS.include?(@element.name)
end