Class: Arrolio::Content::SectionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/content/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, number:, level:, id:, style_id:, title_style_id:) ⇒ SectionBuilder

Returns a new instance of SectionBuilder.



36
37
38
39
40
41
42
43
44
# File 'lib/arrolio/content/builder.rb', line 36

def initialize(title:, number:, level:, id:, style_id:, title_style_id:)
  @title = title
  @number = number
  @level = level
  @id = id
  @style_id = style_id
  @title_style_id = title_style_id
  @children = []
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



34
35
36
# File 'lib/arrolio/content/builder.rb', line 34

def id
  @id
end

#levelObject (readonly)

Returns the value of attribute level.



34
35
36
# File 'lib/arrolio/content/builder.rb', line 34

def level
  @level
end

#numberObject (readonly)

Returns the value of attribute number.



34
35
36
# File 'lib/arrolio/content/builder.rb', line 34

def number
  @number
end

#style_idObject (readonly)

Returns the value of attribute style_id.



34
35
36
# File 'lib/arrolio/content/builder.rb', line 34

def style_id
  @style_id
end

#titleObject (readonly)

Returns the value of attribute title.



34
35
36
# File 'lib/arrolio/content/builder.rb', line 34

def title
  @title
end

#title_style_idObject (readonly)

Returns the value of attribute title_style_id.



34
35
36
# File 'lib/arrolio/content/builder.rb', line 34

def title_style_id
  @title_style_id
end

Instance Method Details

#buildObject



74
75
76
77
# File 'lib/arrolio/content/builder.rb', line 74

def build
  Section.new(title: @title, level: @level, number: @number, id: @id,
              children: @children, style_id: @style_id, title_style_id: @title_style_id)
end

#list(items, kind: :bullet, style_id: :list, id: nil) ⇒ Object



52
53
54
55
# File 'lib/arrolio/content/builder.rb', line 52

def list(items, kind: :bullet, style_id: :list, id: nil)
  @children << List.new(items, kind: kind, style_id: style_id, id: id)
  self
end

#paragraph(text = nil, style_id: :body, id: nil, &block) ⇒ Object



46
47
48
49
50
# File 'lib/arrolio/content/builder.rb', line 46

def paragraph(text = nil, style_id: :body, id: nil, &block)
  runs = block ? ParagraphBuilder.new.runs(&block) : [InlineRun.new(text.to_s, style_id: :inline)]
  @children << Paragraph.new(runs, style_id: style_id, id: id)
  self
end

#section(title = nil, **opts, &block) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/arrolio/content/builder.rb', line 63

def section(title = nil, **opts, &block)
  opts[:level] ||= @level + 1
  sub = SectionBuilder.new(title: title, number: opts[:number],
                           level: opts[:level], id: opts[:id],
                           style_id: opts.fetch(:style_id, @style_id),
                           title_style_id: opts[:title_style_id])
  block&.call(sub)
  @children << sub.build
  self
end

#table(header: [], body: [], column_widths: nil, style_id: :table, id: nil) ⇒ Object



57
58
59
60
61
# File 'lib/arrolio/content/builder.rb', line 57

def table(header: [], body: [], column_widths: nil, style_id: :table, id: nil)
  @children << Table.new(header: header, body: body,
                         column_widths: column_widths, style_id: style_id, id: id)
  self
end