Class: BibTeX::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/bibtex/elements.rb

Overview

The base class for BibTeX objects.

Direct Known Subclasses

Comment, Entry, Error, Preamble, String

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeElement

Returns a new instance of Element.



32
33
34
# File 'lib/bibtex/elements.rb', line 32

def initialize
	@bibliography = nil
end

Instance Attribute Details

#bibliographyObject (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

#contentObject

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_hashObject



46
47
48
# File 'lib/bibtex/elements.rb', line 46

def to_hash
 { self.class.name.downcase => content }
end

#to_jsonObject



54
55
56
# File 'lib/bibtex/elements.rb', line 54

def to_json
  self.to_hash.to_json
end

#to_sObject

Returns a string representation of the object.



42
43
44
# File 'lib/bibtex/elements.rb', line 42

def to_s
	self.content
end

#to_xmlObject



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_yamlObject



50
51
52
# File 'lib/bibtex/elements.rb', line 50

def to_yaml
  self.to_hash.to_yaml
end