Sha256: 6d2fcd480baa50a5c8ff06e6d28fcc6d7c95765848220fe720379d8a900631d8
Contents?: true
Size: 871 Bytes
Versions: 3
Compression:
Stored size: 871 Bytes
Contents
require "chop/definition_list" module Chop class UnorderedList < DefinitionList self.default_selector = "ul" self.rows_finder = ->(root) { root.all("li") } self.cells_finder = ->(row) { [row] } 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 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 end Ul = UnorderedList end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
chop-0.32.0 | lib/chop/unordered_list.rb |
chop-0.31.1 | lib/chop/unordered_list.rb |
chop-0.31.0 | lib/chop/unordered_list.rb |