class Chop::UnorderedList

Public Instance Methods

nested() click to toggle source
# File lib/chop/unordered_list.rb, line 9
def nested
  self.rows_finder = ->(root) {
    recurse_tree [], root
  }
  self.text_finder = ->(cell) {
    cell.chop_prefix + cell.all(:xpath, "*[not(self::ul)]").map(&:text).join(" ").strip
  }
end

Private Instance Methods

recurse_tree(structure, root, prefix: "- ") click to toggle source
# File lib/chop/unordered_list.rb, line 20
def recurse_tree structure, root, prefix: "- "
  root.all(:xpath, "./li").each do |li|
    li.define_singleton_method(:chop_prefix) { prefix }
    structure << li

    if li.has_xpath?("./ul")
      root = li.find(:xpath, "./ul")
      structure = recurse_tree(structure, root, prefix: prefix + "  ")
    end
  end
  structure
end