Class: Coradoc::AsciiDoc::Model::BibliographyEntry

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/asciidoc/model/bibliography_entry.rb

Overview

Individual bibliography entry for AsciiDoc documents.

Bibliography entries represent single references within a bibliography, with anchor names for citation linking.

Examples:

Create a bibliography entry

entry = Coradoc::AsciiDoc::Model::BibliographyEntry.new
entry.anchor_name = "smith2023"
entry.ref_text = "Smith, J. (2023). Example citation."

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#id

Class Method Summary collapse

Methods inherited from Base

#block_level?, #inline?, #serialize_content, #simplify_block_content, #to_adoc, #to_h, visit, #visit

Instance Attribute Details

#anchor_nameString? (readonly)

Returns The anchor name for citing this entry.

Returns:

  • (String, nil)

    The anchor name for citing this entry



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/coradoc/asciidoc/model/bibliography_entry.rb', line 30

class BibliographyEntry < Base
  attribute :anchor_name, :string
  attribute :document_id, :string
  attribute :ref_text, :string
  attribute :line_break, :string, default: -> { '' }

  # Coerce a raw parser AST value into the canonical ref_text string.
  # Accepts the shapes produced by Parser::Bibliography for `:ref_text`:
  # nil, Parslet::Slice, plain String, single Model::Base, or an Array
  # of any of these. Model objects (TextElement, Inline::Italic, etc.)
  # are flattened via TextExtractVisitor so their text content is
  # preserved instead of leaking `#<Class:0x...>` inspect strings.
  # Keeping this coercion on the model that owns ref_text (rather than
  # in a transformer rule) keeps the transformer declarative and lets
  # callers build entries from any source shape.
  # @param raw [Object, nil]
  # @return [String]
  def self.coerce_ref_text(raw)
    return '' if raw.nil?

    case raw
    when Array then raw.map { |e| coerce_ref_text(e) }.join
    when String then raw
    when Coradoc::AsciiDoc::Model::Base
      Coradoc::AsciiDoc::Transform::TextExtractVisitor.new.extract(raw).to_s
    else raw.to_s
    end
  end
end

#document_idString? (readonly)

Returns The document identifier.

Returns:

  • (String, nil)

    The document identifier



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/coradoc/asciidoc/model/bibliography_entry.rb', line 30

class BibliographyEntry < Base
  attribute :anchor_name, :string
  attribute :document_id, :string
  attribute :ref_text, :string
  attribute :line_break, :string, default: -> { '' }

  # Coerce a raw parser AST value into the canonical ref_text string.
  # Accepts the shapes produced by Parser::Bibliography for `:ref_text`:
  # nil, Parslet::Slice, plain String, single Model::Base, or an Array
  # of any of these. Model objects (TextElement, Inline::Italic, etc.)
  # are flattened via TextExtractVisitor so their text content is
  # preserved instead of leaking `#<Class:0x...>` inspect strings.
  # Keeping this coercion on the model that owns ref_text (rather than
  # in a transformer rule) keeps the transformer declarative and lets
  # callers build entries from any source shape.
  # @param raw [Object, nil]
  # @return [String]
  def self.coerce_ref_text(raw)
    return '' if raw.nil?

    case raw
    when Array then raw.map { |e| coerce_ref_text(e) }.join
    when String then raw
    when Coradoc::AsciiDoc::Model::Base
      Coradoc::AsciiDoc::Transform::TextExtractVisitor.new.extract(raw).to_s
    else raw.to_s
    end
  end
end

#line_breakString (readonly)

Returns Line break character (default: “”).

Returns:

  • (String)

    Line break character (default: “”)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/coradoc/asciidoc/model/bibliography_entry.rb', line 30

class BibliographyEntry < Base
  attribute :anchor_name, :string
  attribute :document_id, :string
  attribute :ref_text, :string
  attribute :line_break, :string, default: -> { '' }

  # Coerce a raw parser AST value into the canonical ref_text string.
  # Accepts the shapes produced by Parser::Bibliography for `:ref_text`:
  # nil, Parslet::Slice, plain String, single Model::Base, or an Array
  # of any of these. Model objects (TextElement, Inline::Italic, etc.)
  # are flattened via TextExtractVisitor so their text content is
  # preserved instead of leaking `#<Class:0x...>` inspect strings.
  # Keeping this coercion on the model that owns ref_text (rather than
  # in a transformer rule) keeps the transformer declarative and lets
  # callers build entries from any source shape.
  # @param raw [Object, nil]
  # @return [String]
  def self.coerce_ref_text(raw)
    return '' if raw.nil?

    case raw
    when Array then raw.map { |e| coerce_ref_text(e) }.join
    when String then raw
    when Coradoc::AsciiDoc::Model::Base
      Coradoc::AsciiDoc::Transform::TextExtractVisitor.new.extract(raw).to_s
    else raw.to_s
    end
  end
end

#ref_textString? (readonly)

Returns The reference text/citation.

Returns:

  • (String, nil)

    The reference text/citation



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/coradoc/asciidoc/model/bibliography_entry.rb', line 30

class BibliographyEntry < Base
  attribute :anchor_name, :string
  attribute :document_id, :string
  attribute :ref_text, :string
  attribute :line_break, :string, default: -> { '' }

  # Coerce a raw parser AST value into the canonical ref_text string.
  # Accepts the shapes produced by Parser::Bibliography for `:ref_text`:
  # nil, Parslet::Slice, plain String, single Model::Base, or an Array
  # of any of these. Model objects (TextElement, Inline::Italic, etc.)
  # are flattened via TextExtractVisitor so their text content is
  # preserved instead of leaking `#<Class:0x...>` inspect strings.
  # Keeping this coercion on the model that owns ref_text (rather than
  # in a transformer rule) keeps the transformer declarative and lets
  # callers build entries from any source shape.
  # @param raw [Object, nil]
  # @return [String]
  def self.coerce_ref_text(raw)
    return '' if raw.nil?

    case raw
    when Array then raw.map { |e| coerce_ref_text(e) }.join
    when String then raw
    when Coradoc::AsciiDoc::Model::Base
      Coradoc::AsciiDoc::Transform::TextExtractVisitor.new.extract(raw).to_s
    else raw.to_s
    end
  end
end

Class Method Details

.coerce_ref_text(raw) ⇒ String

Coerce a raw parser AST value into the canonical ref_text string. Accepts the shapes produced by Parser::Bibliography for ‘:ref_text`: nil, Parslet::Slice, plain String, single Model::Base, or an Array of any of these. Model objects (TextElement, Inline::Italic, etc.) are flattened via TextExtractVisitor so their text content is preserved instead of leaking `#<Class:0x…>` inspect strings. Keeping this coercion on the model that owns ref_text (rather than in a transformer rule) keeps the transformer declarative and lets callers build entries from any source shape.

Parameters:

  • raw (Object, nil)

Returns:

  • (String)


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/coradoc/asciidoc/model/bibliography_entry.rb', line 47

def self.coerce_ref_text(raw)
  return '' if raw.nil?

  case raw
  when Array then raw.map { |e| coerce_ref_text(e) }.join
  when String then raw
  when Coradoc::AsciiDoc::Model::Base
    Coradoc::AsciiDoc::Transform::TextExtractVisitor.new.extract(raw).to_s
  else raw.to_s
  end
end