Class: Uniword::Caption::CaptionBuilder
- Inherits:
-
Object
- Object
- Uniword::Caption::CaptionBuilder
- Defined in:
- lib/uniword/caption/caption_builder.rb
Overview
Builds a Caption-styled paragraph for one caption.
Layout of the produced paragraph:
<w:p>
<w:pPr><w:pStyle w:val="Caption"/></w:pPr>
<w:bookmarkStart w:id="N" w:name="_Figure1"/>
<w:r><w:t xml:space="preserve">Figure </w:t></w:r>
<w:fldSimple w:instr=" SEQ Figure \* ARABIC ">
<w:r><w:t>1</w:t></w:r>
</w:fldSimple>
<w:r><w:t xml:space="preserve">: Caption text</w:t></w:r>
<w:bookmarkEnd w:id="N"/>
</w:p>
The bookmark name is _Figure1, _Table2, etc. — _ prefix
matches Word's convention for hidden bookmarks.
Constant Summary collapse
- DEFAULT_SEPARATOR =
": "
Instance Method Summary collapse
-
#build(label:, text:, separator: DEFAULT_SEPARATOR, bookmark_id: nil) ⇒ Array<Wordprocessingml::Paragraph, String>
Build a caption paragraph.
-
#initialize(counter) ⇒ CaptionBuilder
constructor
A new instance of CaptionBuilder.
Constructor Details
#initialize(counter) ⇒ CaptionBuilder
Returns a new instance of CaptionBuilder.
26 27 28 |
# File 'lib/uniword/caption/caption_builder.rb', line 26 def initialize(counter) @counter = counter end |
Instance Method Details
#build(label:, text:, separator: DEFAULT_SEPARATOR, bookmark_id: nil) ⇒ Array<Wordprocessingml::Paragraph, String>
Build a caption paragraph.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/uniword/caption/caption_builder.rb', line 41 def build(label:, text:, separator: DEFAULT_SEPARATOR, bookmark_id: nil) sequence = @counter.next_value(label) bookmark_name = bookmark_name_for(label, sequence) bookmark_id ||= sequence [ build_paragraph(label: label, sequence: sequence, text: text, separator: separator, bookmark_name: bookmark_name, bookmark_id: bookmark_id), bookmark_name, ] end |