Class: AsciidoctorBibtex::BibitemMacro
- Inherits:
-
Object
- Object
- AsciidoctorBibtex::BibitemMacro
- Defined in:
- lib/asciidoctor-bibtex/bibitem_macro.rb
Overview
BibitemMacro
Class to hold information about a bibitem macro. A bibtem macro has only text and key
This class also provides a class method to extract macros from a line of text.
Constant Summary collapse
- BIBITEM_KEY =
matches a bibitem key
/[^\s\]]+/.freeze
- BIBITEM_MACRO =
matches the full macro
/bibitem:\[(#{BIBITEM_KEY})\]/.freeze
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
-
.extract_macros(line) ⇒ Object
Given a line, return a list of BibitemMacro instances.
Instance Method Summary collapse
-
#initialize(text, key) ⇒ BibitemMacro
constructor
Create a BibitemMacro object.
Constructor Details
#initialize(text, key) ⇒ BibitemMacro
Create a BibitemMacro object
text: the full macro text matched by BIBITEM_MACRO key: bibitem key
48 49 50 51 |
# File 'lib/asciidoctor-bibtex/bibitem_macro.rb', line 48 def initialize(text, key) @text = text @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
42 43 44 |
# File 'lib/asciidoctor-bibtex/bibitem_macro.rb', line 42 def key @key end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
42 43 44 |
# File 'lib/asciidoctor-bibtex/bibitem_macro.rb', line 42 def text @text end |
Class Method Details
.extract_macros(line) ⇒ Object
Given a line, return a list of BibitemMacro instances
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/asciidoctor-bibtex/bibitem_macro.rb', line 29 def self.extract_macros(line) result = [] full = BIBITEM_MACRO.match line while full text = full[0] key = full[1] result << BibitemMacro.new(text, key) # look for next citation on line full = BIBITEM_MACRO.match full.post_match end result end |