Class: Peregrin::Outliner::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/peregrin/outliner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node = nil) ⇒ Section

Returns a new instance of Section.



57
58
59
60
# File 'lib/peregrin/outliner.rb', line 57

def initialize(node = nil)
  self.node = node
  self.sections = []
end

Instance Attribute Details

#containerObject

Returns the value of attribute container.



54
55
56
# File 'lib/peregrin/outliner.rb', line 54

def container
  @container
end

#headingObject

Returns the value of attribute heading.



54
55
56
# File 'lib/peregrin/outliner.rb', line 54

def heading
  @heading
end

#nodeObject

Returns the value of attribute node.



54
55
56
# File 'lib/peregrin/outliner.rb', line 54

def node
  @node
end

#sectionsObject

Returns the value of attribute sections.



54
55
56
# File 'lib/peregrin/outliner.rb', line 54

def sections
  @sections
end

Instance Method Details

#append(subsection) ⇒ Object



63
64
65
66
# File 'lib/peregrin/outliner.rb', line 63

def append(subsection)
  subsection.container = self
  sections.push(subsection)
end

#empty?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/peregrin/outliner.rb', line 69

def empty?
  heading_text.nil? && sections.all? { |sxn| sxn.empty? }
end

#heading_rankObject



83
84
85
86
# File 'lib/peregrin/outliner.rb', line 83

def heading_rank
  # FIXME: some doubt as to whether 1 is the sensible default
  Utils.heading?(heading) ? Utils.heading_rank(heading) : 1
end

#heading_textObject



74
75
76
77
78
79
80
# File 'lib/peregrin/outliner.rb', line 74

def heading_text
  return nil  unless Utils.heading?(heading)
  h = heading
  h = h.at_css("h#{Utils.heading_rank(h)}")  if Utils.named?(h, 'HGROUP')
  return  nil  unless h && !h.content.strip.empty?
  h.content.strip
end