class HippoXmlParser::Crawler

Constants

TYPES

Attributes

types[R]

Public Class Methods

new(doc, types=[]) click to toggle source
# File lib/hippo_xml_parser/crawler.rb, line 13
def initialize(doc, types=[])
  @doc = doc
  @types = Array(types).empty? ? TYPES : Array(types)
end

Public Instance Methods

all() click to toggle source
# File lib/hippo_xml_parser/crawler.rb, line 39
def all
  crawl( nodes(@doc).first ).flatten
end
crawl(doc) click to toggle source
# File lib/hippo_xml_parser/crawler.rb, line 31
def crawl(doc)
  if type?(doc, types)
    Article.new(doc)
  else
    doc.children.map {|e| crawl(e) }
  end
end
nodes(doc) click to toggle source
# File lib/hippo_xml_parser/crawler.rb, line 18
def nodes(doc)
  doc.children.select {|e| e.name == "node" }
end
type?(el, names) click to toggle source
# File lib/hippo_xml_parser/crawler.rb, line 22
def type?(el, names)
  el.children.map do |e|
    if  e.name == "property" && e["sv:name"] == "jcr:primaryType"

      e if e.children.select {|x| x.name == "value" && Array(names).include?(x.children.to_s) }.any?
    end
  end.flatten.compact.first
end