Class: BibTeX::Names
- Inherits:
-
Value
- Object
- Value
- BibTeX::Names
show all
- Includes:
- Enumerable
- Defined in:
- lib/bibtex/names.rb
Overview
A BibTeX Names value is an ordered list of name values.
Instance Attribute Summary
Attributes inherited from Value
#tokens
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Value
#convert, #convert!, create, #date?, #include_token?, #initialize_copy, #inspect, #merge, #merge!, #method_missing, #respond_to?, #symbols, #to_date, #to_i
Constructor Details
#initialize(*arguments) ⇒ Names
Returns a new instance of Names.
35
36
37
38
39
40
|
# File 'lib/bibtex/names.rb', line 35
def initialize(*arguments)
@tokens = []
arguments.flatten.compact.each do |argument|
add(argument)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class BibTeX::Value
Class Method Details
.parse(string) ⇒ Object
28
29
30
31
32
33
|
# 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
|
Instance Method Details
#<=>(other) ⇒ Object
109
110
111
|
# File 'lib/bibtex/names.rb', line 109
def <=>(other)
other.respond_to?(:to_a) ? to_a <=> other.to_a : super
end
|
#add(name) ⇒ Object
Also known as:
<<, push
88
89
90
91
92
93
94
95
96
97
|
# 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? ⇒ Boolean
69
70
71
|
# File 'lib/bibtex/names.rb', line 69
def atomic?
true
end
|
#join ⇒ Object
46
47
48
|
# File 'lib/bibtex/names.rb', line 46
def join
self
end
|
#name? ⇒ Boolean
Also known as:
names?
61
62
63
|
# File 'lib/bibtex/names.rb', line 61
def name?
true
end
|
#numeric? ⇒ Boolean
Also known as:
symbol?
65
66
67
|
# File 'lib/bibtex/names.rb', line 65
def numeric?
false
end
|
#replace(*_arguments) ⇒ Object
42
43
44
|
# File 'lib/bibtex/names.rb', line 42
def replace(*_arguments)
self
end
|
#strip_braces ⇒ Object
84
85
86
|
# File 'lib/bibtex/names.rb', line 84
def strip_braces
gsub!(/\{|\}/, '')
end
|
#to_citeproc(options = {}) ⇒ Object
80
81
82
|
# File 'lib/bibtex/names.rb', line 80
def to_citeproc(options = {})
map { |n| n.to_citeproc(options) }
end
|
#to_name ⇒ Object
76
77
78
|
# File 'lib/bibtex/names.rb', line 76
def to_name
self
end
|
#to_s(options = {}) ⇒ Object
54
55
56
57
58
59
|
# 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 = {}) ⇒ Object
50
51
52
|
# File 'lib/bibtex/names.rb', line 50
def value(options = {})
@tokens.map { |n| n.to_s(options) }.join(' and ')
end
|