Class: BibTeX::Element
- Inherits:
-
Object
- Object
- BibTeX::Element
- Defined in:
- lib/bibtex/elements.rb
Overview
The base class for BibTeX objects.
Instance Attribute Summary collapse
-
#bibliography ⇒ Object
readonly
Returns the value of attribute bibliography.
Instance Method Summary collapse
-
#added_to_bibliography(bibliography) ⇒ Object
Called when the element was added to a bibliography.
-
#content ⇒ Object
Returns a string containing the object’s content.
-
#initialize ⇒ Element
constructor
A new instance of Element.
-
#removed_from_bibliography(bibliography) ⇒ Object
Called when the element was removed from a bibliography.
- #to_hash ⇒ Object
- #to_json ⇒ Object
-
#to_s ⇒ Object
Returns a string representation of the object.
- #to_xml ⇒ Object
- #to_yaml ⇒ Object
Constructor Details
#initialize ⇒ Element
Returns a new instance of Element.
32 33 34 |
# File 'lib/bibtex/elements.rb', line 32 def initialize @bibliography = nil end |
Instance Attribute Details
#bibliography ⇒ Object (readonly)
Returns the value of attribute bibliography.
30 31 32 |
# File 'lib/bibtex/elements.rb', line 30 def bibliography @bibliography end |
Instance Method Details
#added_to_bibliography(bibliography) ⇒ Object
Called when the element was added to a bibliography.
65 66 67 68 |
# File 'lib/bibtex/elements.rb', line 65 def added_to_bibliography(bibliography) @bibliography = bibliography self end |
#content ⇒ Object
Returns a string containing the object’s content.
37 38 39 |
# File 'lib/bibtex/elements.rb', line 37 def content "" end |
#removed_from_bibliography(bibliography) ⇒ Object
Called when the element was removed from a bibliography.
71 72 73 74 |
# File 'lib/bibtex/elements.rb', line 71 def removed_from_bibliography(bibliography) @bibliography = nil self end |
#to_hash ⇒ Object
46 47 48 |
# File 'lib/bibtex/elements.rb', line 46 def to_hash { self.class.name.downcase => content } end |
#to_json ⇒ Object
54 55 56 |
# File 'lib/bibtex/elements.rb', line 54 def to_json self.to_hash.to_json end |
#to_s ⇒ Object
Returns a string representation of the object.
42 43 44 |
# File 'lib/bibtex/elements.rb', line 42 def to_s self.content end |
#to_xml ⇒ Object
58 59 60 61 62 |
# File 'lib/bibtex/elements.rb', line 58 def to_xml xml = REXML::Element.new(self.class.name.downcase) xml.text = self.content xml end |
#to_yaml ⇒ Object
50 51 52 |
# File 'lib/bibtex/elements.rb', line 50 def to_yaml self.to_hash.to_yaml end |