class BibTeX::String
Represents a @string object.
In BibTeX @string objects contain a single string constant assignment. For example, @string{ foo = “bar” } defines the constant `foo'; this constant can be used (using BibTeX's string concatenation syntax) in susbsequent @string and @preamble objects, as well as in field values of regular entries.
Attributes
key[R]
Public Class Methods
new(key = nil, value = nil) { |self| ... }
click to toggle source
Creates a new instance.
# File lib/bibtex/elements.rb, line 262 def initialize(key = nil, value = nil) @key = key.to_sym @value = Value.new(value) yield self if block_given? end
Public Instance Methods
[](key)
click to toggle source
Retuns the string's value if parameter matches the key; nil otherwise.
# File lib/bibtex/elements.rb, line 281 def [](key) @key == key ? @value : nil end
added_to_bibliography(bibliography)
click to toggle source
Called when the element was added to a bibliography.
Calls superclass method
BibTeX::Element#added_to_bibliography
# File lib/bibtex/elements.rb, line 286 def added_to_bibliography(bibliography) super bibliography.strings[@key] = self self end
content()
click to toggle source
Returns a string representation of the @string's content.
# File lib/bibtex/elements.rb, line 300 def content "#{@key} = #{@value.to_s(quotes: '"')}" end
key=(key)
click to toggle source
Sets the string's key (i.e., the symbol identifying the constant).
# File lib/bibtex/elements.rb, line 269 def key=(key) raise(ArgumentError, "keys must be convertible to Symbol; was: #{type.class.name}.") unless type.respond_to?(:to_sym) unless bibliography.nil? bibliography.strings.delete(@key) bibliography.strings[key.to_sym] = self end @key = key.to_sym end
removed_from_bibliography(bibliography)
click to toggle source
Called when the element was removed from a bibliography.
Calls superclass method
BibTeX::Element#removed_from_bibliography
# File lib/bibtex/elements.rb, line 293 def removed_from_bibliography(bibliography) super bibliography.strings[@key] = nil self end
to_hash(_options = {})
click to toggle source
# File lib/bibtex/elements.rb, line 309 def to_hash(_options = {}) { string: { @key => @value.to_s(quotes: '"') } } end
to_s(_options = {})
click to toggle source
Returns a string representation of the @string object.
# File lib/bibtex/elements.rb, line 305 def to_s(_options = {}) "@string{ #{content} }\n" end
to_xml(_options = {})
click to toggle source
# File lib/bibtex/elements.rb, line 313 def to_xml(_options = {}) require 'rexml/document' xml = REXML::Element.new(:string) k = REXML::Element.new(:key) v = REXML::Element.new(:value) k.text = key.to_s v.text = value.to_s(quotes: '"') xml.add_elements(k) xml.add_elements(v) xml end