Class: MD::Page

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/md2slides/md.rb

Defined Under Namespace

Classes: Element

Instance Method Summary collapse

Constructor Details

#initializePage



16
17
18
19
# File 'lib/md2slides/md.rb', line 16

def initialize
  @elements = []
  @comments = []
end

Instance Method Details

#add(type, value, attributes = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/md2slides/md.rb', line 21

def add(type, value, attributes = nil)
  return if value.nil? || value.empty?
  case type.to_s
  when /^h([0-9]+)$/
    n = $1.to_i - 1
    attributes ||= {}
    attributes[:indent] = n
  end
  @elements.push(Element.new(type, value, attributes))
end

#add_comment(c) ⇒ Object



32
33
34
35
# File 'lib/md2slides/md.rb', line 32

def add_comment(c)
  return if c.nil? || c.empty?
  @comments.push(c)
end

#commentsObject



37
38
39
40
# File 'lib/md2slides/md.rb', line 37

def comments
  return nil if @comments.empty?
  @comments.join("\n")
end

#each(&block) ⇒ Object



67
68
69
# File 'lib/md2slides/md.rb', line 67

def each(&block)
  @elements.drop(has_title? ? 1 : 0).each(&block)
end

#has_comments?Boolean



42
43
44
# File 'lib/md2slides/md.rb', line 42

def has_comments?
  ! @comments.empty?
end

#has_title?Boolean



46
47
48
# File 'lib/md2slides/md.rb', line 46

def has_title?
  @elements[0]&.type == :h1
end

#subtitleObject



63
64
65
# File 'lib/md2slides/md.rb', line 63

def subtitle
  title_subtitle_only? && @elements[1]&.value
end

#titleObject



50
51
52
# File 'lib/md2slides/md.rb', line 50

def title
  has_title? && @elements[0].value
end

#title_only?Boolean



54
55
56
# File 'lib/md2slides/md.rb', line 54

def title_only?
  has_title? && @elements.size == 1
end

#title_subtitle_only?Boolean



58
59
60
61
# File 'lib/md2slides/md.rb', line 58

def title_subtitle_only?
  has_title? && @elements.size == 2 &&
      @elements[1]&.type == :h2
end