Module: BibTeX::StringReplacement

Defined in:
lib/bibtex/string_replacement.rb

Overview

This module contains functions to manipulate BibTeX string literals.

Class Method Summary collapse

Class Method Details

.replace(value, hsh) ⇒ Object

Replaces all string constants in value which are defined in hsh.



38
39
40
41
# File 'lib/bibtex/string_replacement.rb', line 38

def self.replace(value,hsh)
	return if value.nil?
	value.map { |s| s.kind_of?(Symbol) && hsh.has_key?(s) ? hsh[s] : s }.flatten
end

.to_s(value, options = {}) ⇒ Object

Returns a string representation of the literal.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bibtex/string_replacement.rb', line 25

def self.to_s(value,options={})
	return if value.nil?
	options[:delimiter] ||= ['"','"']
	#options[:delimiter] ||= ['{','}']

	if value.empty? || (value.length == 1 && !value[0].kind_of?(Symbol))
		[options[:delimiter][0],value,options[:delimiter][1]].join
	else
		value.map { |s| s.kind_of?(Symbol) ? s.to_s : s.inspect}.join(' # ')
	end
end