Class: Uniword::Builder::BibliographyBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/builder/bibliography_builder.rb

Overview

Builds bibliography sources for a document.

Manages the Bibliography::Sources collection, providing factory methods for common source types (book, journal article, website, etc.).

Examples:

Create sources and attach to a document

bib = BibliographyBuilder.new
bib.book(tag: 'Smith2024', author: ['John Smith'],
         title: 'The Book', year: '2024', publisher: 'ACME')
bib.journal(tag: 'Doe2023', author: ['Jane Doe'],
           title: 'The Paper', year: '2023',
           journal: 'Nature', volume: '42', pages: '1-10')
bib.attach(document)

Insert bibliography placeholder

doc.paragraph { |p| p << SdtBuilder.bibliography.build }

Constant Summary collapse

CHART_REL_TYPE =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/bibliography"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style: "APA") ⇒ BibliographyBuilder

Returns a new instance of BibliographyBuilder.



27
28
29
30
31
# File 'lib/uniword/builder/bibliography_builder.rb', line 27

def initialize(style: "APA")
  @sources = Bibliography::Sources.new
  @sources.selected_style = style
  @ref_order_counter = 0
end

Instance Attribute Details

#sourcesObject (readonly)

Returns the value of attribute sources.



25
26
27
# File 'lib/uniword/builder/bibliography_builder.rb', line 25

def sources
  @sources
end

Instance Method Details

#attach(document) ⇒ self

Attach the bibliography sources to a document

Parameters:

Returns:

  • (self)


37
38
39
40
41
# File 'lib/uniword/builder/bibliography_builder.rb', line 37

def attach(document)
  root = document.respond_to?(:model) ? document.model : document
  root.bibliography_sources = @sources
  self
end

#book(tag:, author:, title:, year:, publisher:, city: nil, edition: nil) ⇒ self

Create a book source

Parameters:

  • tag (String)

    Unique tag identifier (e.g., ‘Smith2024’)

  • author (Array<String>)

    List of author names (format: ‘First Last’)

  • title (String)

    Book title

  • year (String)

    Publication year

  • publisher (String)

    Publisher name

  • city (String, nil) (defaults to: nil)

    Publisher city

  • edition (String, nil) (defaults to: nil)

    Edition

Returns:

  • (self)


53
54
55
56
57
58
59
60
61
# File 'lib/uniword/builder/bibliography_builder.rb', line 53

def book(tag:, author:, title:, year:, publisher:,
         city: nil, edition: nil)
  src = build_source("Book", tag: tag, author: author,
                             title: title, year: year,
                             publisher: publisher, city: city,
                             edition: edition)
  @sources.source << src
  self
end

#buildBibliography::Sources

Build and return the Sources model



146
147
148
# File 'lib/uniword/builder/bibliography_builder.rb', line 146

def build
  @sources
end

#conference(tag:, author:, title:, year:, publisher:, city: nil) ⇒ self

Create a conference proceedings source

Parameters:

  • tag (String)

    Unique tag identifier

  • author (Array<String>)

    List of author names

  • title (String)

    Paper title

  • year (String)

    Publication year

  • publisher (String)

    Conference/organization name

  • city (String, nil) (defaults to: nil)

    Conference location

Returns:

  • (self)


108
109
110
111
112
113
114
115
# File 'lib/uniword/builder/bibliography_builder.rb', line 108

def conference(tag:, author:, title:, year:, publisher:,
               city: nil)
  src = build_source("ConferenceProceedings", tag: tag,
                                              author: author, title: title, year: year,
                                              publisher: publisher, city: city)
  @sources.source << src
  self
end

#journal(tag:, author:, title:, year:, journal:, volume: nil, issue: nil, pages: nil) ⇒ self

Create a journal article source

Parameters:

  • tag (String)

    Unique tag identifier

  • author (Array<String>)

    List of author names

  • title (String)

    Article title

  • year (String)

    Publication year

  • journal (String)

    Journal name

  • volume (String, nil) (defaults to: nil)

    Volume number

  • issue (String, nil) (defaults to: nil)

    Issue number

  • pages (String, nil) (defaults to: nil)

    Page range

Returns:

  • (self)


74
75
76
77
78
79
80
81
82
# File 'lib/uniword/builder/bibliography_builder.rb', line 74

def journal(tag:, author:, title:, year:, journal:,
            volume: nil, issue: nil, pages: nil)
  src = build_source("JournalArticle", tag: tag, author: author,
                                       title: title, year: year,
                                       publisher: journal, volume: volume,
                                       issue: issue, pages: pages)
  @sources.source << src
  self
end

#source(tag:, source_type:, title:, author: nil, year: nil) ⇒ self

Create a generic/artistic source

Parameters:

  • tag (String)

    Unique tag identifier

  • source_type (String)

    OOXML source type string

  • title (String)

    Title

  • author (Array<String>, nil) (defaults to: nil)

    List of author names

  • year (String, nil) (defaults to: nil)

    Year

  • kwargs (Hash)

    Additional fields (publisher, url, pages, etc.)

Returns:

  • (self)


126
127
128
129
130
131
132
# File 'lib/uniword/builder/bibliography_builder.rb', line 126

def source(tag:, source_type:, title:, author: nil,
           year: nil, **)
  src = build_source(source_type, tag: tag, author: author,
                                  title: title, year: year, **)
  @sources.source << src
  self
end

#style=(style) ⇒ self

Set the citation style

Parameters:

  • style (String)

    Style name (e.g., ‘APA’, ‘MLA’, ‘Chicago’)

Returns:

  • (self)


138
139
140
141
# File 'lib/uniword/builder/bibliography_builder.rb', line 138

def style=(style)
  @sources.selected_style = style
  self
end

#website(tag:, title:, url:, author: nil, year: nil) ⇒ self

Create a website source

Parameters:

  • tag (String)

    Unique tag identifier

  • author (Array<String>, nil) (defaults to: nil)

    List of author names

  • title (String)

    Page title

  • year (String, nil) (defaults to: nil)

    Publication/access year

  • url (String)

    URL

Returns:

  • (self)


92
93
94
95
96
97
# File 'lib/uniword/builder/bibliography_builder.rb', line 92

def website(tag:, title:, url:, author: nil, year: nil)
  src = build_source("InternetSite", tag: tag, author: author,
                                     title: title, year: year, url: url)
  @sources.source << src
  self
end