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.
Creates a new instance.
# File lib/bibtex/elements.rb, line 253 def initialize(key = nil, value = nil) @key, @value = key.to_sym, Value.new(value) yield self if block_given? end
Retuns the string's value if parameter matches the key; nil otherwise.
# File lib/bibtex/elements.rb, line 271 def [](key) @key == key ? @value : nil end
Called when the element was added to a bibliography.
# File lib/bibtex/elements.rb, line 277 def added_to_bibliography(bibliography) super bibliography.strings[@key] = self self end
Returns a string representation of the @string's content.
# File lib/bibtex/elements.rb, line 291 def content "#@key = #{@value.to_s(:quotes => '"')}" end
Sets the string's key (i.e., the symbol identifying the constant).
# File lib/bibtex/elements.rb, line 259 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
Called when the element was removed from a bibliography.
# File lib/bibtex/elements.rb, line 284 def removed_from_bibliography(bibliography) super bibliography.strings[@key] = nil self end
# File lib/bibtex/elements.rb, line 300 def to_hash(options = {}) { :string => { @key => @value.to_s(:quotes => '"') } } end
Returns a string representation of the @string object.
# File lib/bibtex/elements.rb, line 296 def to_s(options = {}) "@string{ #{content} }\n" end
# File lib/bibtex/elements.rb, line 304 def to_xml(options = {}) require 'rexml/document' xml = REXML::Element.new(:string) k, v = REXML::Element.new(:key), 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