Class: BibTeX::Preamble

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

Overview

Represents a @preamble object.

In BibTeX an @preamble object contains a single string literal, a single constant, or a concatenation of string literals and constants.

Instance Attribute Summary

Attributes inherited from Element

#bibliography

Instance Method Summary collapse

Methods inherited from Element

#<=>, #added_to_bibliography, parse, #removed_from_bibliography, #to_hash, #to_json, #to_xml, #to_yaml

Constructor Details

#initialize(value = []) ⇒ Preamble

Creates a new instance.



211
212
213
# File 'lib/bibtex/elements.rb', line 211

def initialize(value=[])
	self.value = value
end

Instance Method Details

#contentObject

Returns a string representation of the @preamble’s content.



237
238
239
# File 'lib/bibtex/elements.rb', line 237

def content
	@value.to_s(:quotes => %w(" "))
end

#join!Object



228
229
230
# File 'lib/bibtex/elements.rb', line 228

def join!
  @value = @value.join_strings
end

#replace(hash) ⇒ Object



220
221
222
# File 'lib/bibtex/elements.rb', line 220

def replace(hash)
	@value.replace_strings(hash)
end

#replace!(hash) ⇒ Object



224
225
226
# File 'lib/bibtex/elements.rb', line 224

def replace!(hash)
	@value = @value.replace_strings(hash)
end

#to_sObject

Returns a string representation of the @preamble object



242
243
244
# File 'lib/bibtex/elements.rb', line 242

def to_s
	"@preamble{ #{ content } }"
end

#valueObject



232
233
234
# File 'lib/bibtex/elements.rb', line 232

def value
  content
end

#value=(value) ⇒ Object

Raises:

  • (ArgumentError)


215
216
217
218
# File 'lib/bibtex/elements.rb', line 215

def value=(value)
	raise(ArgumentError, "BibTeX::Preamble value must be of type Array, Symbol, or String; was: #{value.class.name}.") unless [Array,::String,Symbol].map { |k| value.is_a?(k) }.inject { |sum,n| sum || n }
	@value = Extensions.string_replacement(value.is_a?(Array) ? value : [value])
end