chop 0.22.1 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18cb4900f0bba25d3f588ab577061e98f7c76652
4
- data.tar.gz: dcde9c227d8676b0ec2cb25edfc4b3756d96e68e
3
+ metadata.gz: 925b1cafceddaff0b665cc7478d808ef08a04cfc
4
+ data.tar.gz: 7f9198af9e9d99946c8735ae2761a333d32aa219
5
5
  SHA512:
6
- metadata.gz: 1e8631cb632f0dcc7dbc537fcd1f848c7d6d296385fbd96f6da6b947488e8f76bda3a23cfe7baf63c8a9f7fb059bd2eac1fceac9efc6f659e6c4aba0c68e9278
7
- data.tar.gz: 5232dd6b3a332fa9e31c5dac1a5a76494aeae9373539805514e43f9fb9332a0ad703c72f6d1c4bd5dc525a1f80cc98dac96052bc9a99ecd5482857a11d26c486
6
+ metadata.gz: 1b745708d9f7de22ac6ef9475b9d5d4b0732c1ebf80712e8b8052418a3b1a82b47419d026afc1219629280207f48852639fa709ab5c0340a97d9bfd0969a9b5b
7
+ data.tar.gz: 4a093d72ae1d391cff2bb48688c3b5513602a1c2e72a5886845e1fa57a4c6e4b4614fc46b229fb6dd6ed6e9eba90c757c7bf5211a07d194b09827fb88ba632a9
@@ -5,6 +5,30 @@ module Chop
5
5
  self.default_selector = "ul"
6
6
  self.rows_finder = ->(root) { root.all("li") }
7
7
  self.cells_finder = ->(row) { [row] }
8
+
9
+ def nested
10
+ self.rows_finder = ->(root) {
11
+ recurse_tree [], root
12
+ }
13
+ self.text_finder = ->(cell) {
14
+ cell.chop_prefix + cell.all(:xpath, "*[not(self::ul)]").map(&:text).join(" ").strip
15
+ }
16
+ end
17
+
18
+ private
19
+
20
+ def recurse_tree structure, root, prefix: "- "
21
+ root.all(:xpath, "./li").each do |li|
22
+ li.define_singleton_method(:chop_prefix) { prefix }
23
+ structure << li
24
+
25
+ if li.has_xpath?("./ul")
26
+ root = li.find(:xpath, "./ul")
27
+ structure = recurse_tree(structure, root, prefix: prefix + " ")
28
+ end
29
+ end
30
+ structure
31
+ end
8
32
  end
9
33
 
10
34
  Ul = UnorderedList
data/lib/chop/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Chop
2
- VERSION = "0.22.1"
2
+ VERSION = "0.23.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.1
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-23 00:00:00.000000000 Z
11
+ date: 2018-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord