lib/infoboxer/navigation/sections.rb in infoboxer-0.3.3 vs lib/infoboxer/navigation/sections.rb in infoboxer-0.4.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + module Infoboxer module Navigation # `Sections` module provides logical view on document strcture. # # From this module's point of view, each {Tree::Document Document} is a @@ -73,18 +75,19 @@ when 0 @sections when 1 @sections.select { |s| names.first === s.heading.text_ } else - @sections.select { |s| names.first === s.heading.text_ }.sections(*names[1..-1]) + @sections.select { |s| names.first === s.heading.text_ }.sections(*names[1..]) end end def subsections(*names) sections = names.map { |name| heading = lookup_children(:Heading, text_: name).first next unless heading + body = heading.next_siblings .take_while { |n| !n.is_a?(Tree::Heading) || n.level > heading.level } Section.new(heading, body) }.compact @@ -102,9 +105,10 @@ private def make_sections res = Tree::Nodes[] return res if headings.empty? + level = headings.first.level children .chunk { |n| n.matches?(Tree::Heading, level: level) } .drop_while { |is_heading, _nodes| !is_heading }