Class: Peregrin::Outliner::Utils

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

Class Method Summary collapse

Class Method Details

.element_name_is?(el, pattern) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
# File 'lib/peregrin/outliner.rb', line 42

def self.element_name_is?(el, pattern)
  return false  unless el
  return false  unless el.respond_to?(:name)
  return false  if el.name.nil? || el.name.empty?
  el.name.upcase.match(pattern) ? true : false
end

.heading?(el) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/peregrin/outliner.rb', line 21

def self.heading?(el)
  element_name_is?(el, REGEXES[:heading])
end

.heading_rank(el) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/peregrin/outliner.rb', line 31

def self.heading_rank(el)
  raise "Not a heading: #{el.inspect}"  unless heading?(el)
  if named?(el, 'HGROUP')
    1.upto(6) { |n| return n  if el.at_css("h#{n}") }
    return 6 #raise "Heading not found in HGROUP: #{el.inspect}"
  else
    el.name.reverse.to_i
  end
end

.named?(el, name) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/peregrin/outliner.rb', line 26

def self.named?(el, name)
  element_name_is?(el, /^#{name}$/)
end

.section_content?(el) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/peregrin/outliner.rb', line 16

def self.section_content?(el)
  element_name_is?(el, REGEXES[:section_content])
end

.section_root?(el) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/peregrin/outliner.rb', line 11

def self.section_root?(el)
  element_name_is?(el, REGEXES[:section_root])
end