class BibTeX::Names

A BibTeX Names value is an ordered list of name values.

Public Class Methods

new(*arguments) click to toggle source
# File lib/bibtex/names.rb, line 36
def initialize(*arguments)
  @tokens = []
  arguments.flatten.compact.each do |argument|
    add(argument)
  end
end
parse(string) click to toggle source
# File lib/bibtex/names.rb, line 29
def self.parse(string)
  new(NameParser.new.parse(string))
rescue => e
  BibTeX.log.info(e.message)
  nil
end

Public Instance Methods

<<(name)
Alias for: add
<=>(other) click to toggle source
Calls superclass method
# File lib/bibtex/names.rb, line 110
def <=>(other)
  other.respond_to?(:to_a) ? to_a <=> other.to_a  : super
end
add(name) click to toggle source
# File lib/bibtex/names.rb, line 88
def add(name)
  case
  when name.is_a?(Name)
    @tokens << name
  when name.respond_to?(:to_s)
    @tokens += Names.parse(name.to_s)
  else
    raise ArgumentError, "failed to add #{name.inspect}: not a name."
  end
  self
end
Also aliased as: <<, push
atomic?() click to toggle source
# File lib/bibtex/names.rb, line 69
def atomic?
  true
end
join() click to toggle source
# File lib/bibtex/names.rb, line 47
def join
  self
end
name?() click to toggle source
# File lib/bibtex/names.rb, line 61
def name?
  true
end
Also aliased as: names?
names?()
Alias for: name?
numeric?() click to toggle source
# File lib/bibtex/names.rb, line 65
def numeric?
  false
end
Also aliased as: symbol?
push(name)
Alias for: add
replace(*arguments) click to toggle source
# File lib/bibtex/names.rb, line 43
def replace(*arguments)
  self
end
strip_braces() click to toggle source
# File lib/bibtex/names.rb, line 84
def strip_braces
  gsub!(/\{|\}/,'')
end
symbol?()
Alias for: numeric?
to_citeproc(options = {}) click to toggle source
# File lib/bibtex/names.rb, line 80
def to_citeproc(options = {})
  map { |n| n.to_citeproc(options) }
end
to_name() click to toggle source
# File lib/bibtex/names.rb, line 76
def to_name
  self
end
to_s(options = {}) click to toggle source
# File lib/bibtex/names.rb, line 55
def to_s(options = {})
  return value unless options.has_key?(:quotes)
  q = [options[:quotes]].flatten
  [q[0], value, q[-1]].compact.join
end
value(options = {}) click to toggle source
# File lib/bibtex/names.rb, line 51
def value(options = {})
  @tokens.map { |n| n.to_s(options) }.join(' and ')
end