Class: HMachine::Microformat::XOXO

Inherits:
POSH::Base show all
Defined in:
lib/hmachine/microformat/xoxo.rb

Constant Summary collapse

FRIENDLY_NAME =
"XOXO"
WIKI_URL =
'http://microformats.org/wiki/xoxo'
XMDP =
'http://microformats.org/profile/xoxo'

Constants included from HMachine

PRODID, VERSION

Instance Attribute Summary

Attributes inherited from POSH::Base

#node, #parent, #source

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from POSH::Base

[], add_property, #each_pair, #empty?, extract, get_properties, has_many, has_many!, has_one, has_one!, #has_property?, inherited, #initialize, #inspect, many, name, one, parent, #properties, properties, property_of?, remove_nested, search, selector, #to_h, #to_html, #to_s, validate

Methods included from HMachine

#extract, #extract_from, find, #find_in, #found_in?, get, get_document, get_url, map, normalize, #parse, #parse_first, #search, #valid?, #validate

Constructor Details

This class inherits a constructor from HMachine::POSH::Base

Class Method Details

.build_outline(node) ⇒ Object

Seriously ugly WTF



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/hmachine/microformat/xoxo.rb', line 11

def self.build_outline(node)
  tree = []
  node.children.each do |child|
    if child.elem? && 
      case child.node_name
        when 'li'
          if child.children.select {|li| li.elem? }.empty?
            tree = tree | build_outline(child)
          else
            tree << build_outline(child)
          end
        when 'ol', 'ul'
          tree << build_outline(child)
        when 'dl'
          definition_list = {}
          keys = child.css('dt')
          keys.each do |key|
            definition = key.next_element if key.next_element.node_name.eql?('dd')
            definition_contents = definition.children.select {|dd| dd.elem? }
            definition_list.merge!({ key.content.strip => (definition_contents.empty? ? definition.content.to_s : build_outline(definition)) })
          end
          tree << definition_list
        when 'a'
          link = { :url => child['href'], :text => child.content.strip }
          link[:rel] = child['rel'].split(' ') if child['rel']
          link[:type] = child['type'] if child['type']
          link[:title] = child['title'] if child['title']
          tree << link
        else
          tree << child.content.strip
      end
    elsif (child.text? && !child.content.strip.empty?)
      tree << child.content.strip
    end
  end
  tree
end

Instance Method Details

#[](index) ⇒ Object



57
58
59
# File 'lib/hmachine/microformat/xoxo.rb', line 57

def [](index)
  outline[index]
end

#blogroll?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/hmachine/microformat/xoxo.rb', line 61

def blogroll?
  node['class'].split.include?('blogroll')
end

#outlineObject



49
50
51
# File 'lib/hmachine/microformat/xoxo.rb', line 49

def outline
  @outline ||= self.class.build_outline(node)
end

#to_aObject



53
54
55
# File 'lib/hmachine/microformat/xoxo.rb', line 53

def to_a
  outline
end