class BibTeX::Names
Public Class Methods
new(*arguments)
click to toggle source
# File lib/bibtex/names.rb, line 35 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 28 def self.parse(string) new(NameParser.new.parse(string)) rescue StandardError => e BibTeX.log.info(e.message) nil end
Public Instance Methods
<=>(other)
click to toggle source
Calls superclass method
# File lib/bibtex/names.rb, line 109 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) if name.is_a?(Name) @tokens << name elsif 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
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 46 def join self end
name?()
click to toggle source
# File lib/bibtex/names.rb, line 61 def name? true end
Also aliased as: names?
numeric?()
click to toggle source
# File lib/bibtex/names.rb, line 65 def numeric? false end
Also aliased as: symbol?
replace(*_arguments)
click to toggle source
# File lib/bibtex/names.rb, line 42 def replace(*_arguments) self end
strip_braces()
click to toggle source
# File lib/bibtex/names.rb, line 84 def strip_braces gsub!(/\{|\}/, '') end
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 54 def to_s(options = {}) return value unless options.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 50 def value(options = {}) @tokens.map { |n| n.to_s(options) }.join(' and ') end