Class: CSL::Style::Name
Instance Attribute Summary
Attributes inherited from Node
#attributes
Attributes included from Treelike
#children, #nodename, #parent
Instance Method Summary
collapse
inherits
Methods inherited from Node
#<=>, #attribute?, #attributes?, #attributes_for, constantize, create, create_attributes, #custom_attributes, #deep_copy, #default_attribute?, #default_attributes, default_attributes, #each, #exact_match?, #format_page_ranges?, #formatting_options, #has_attributes?, #has_default_attributes?, #has_language?, hide_default_attributes!, hide_default_attributes?, #initialize_copy, #inspect, match?, #match?, matches?, #merge!, #page_range_format, parse, parse!, #quotes?, #reverse_merge!, #save_to, show_default_attributes!, #strip_periods?, #tags, #textnode?, types
#nesting
#pretty_print, #tags, #to_xml
Methods included from Treelike
#<<, #add_child, #add_children, #ancestors, #closest, #delete_child, #delete_children, #depth, #descendants, #each_ancestor, #each_child, #each_descendant, #each_sibling, #empty?, #find_child, #find_children, #has_children?, #root, #root?, #siblings, #unlink
Constructor Details
#initialize(attributes = {}) {|_self| ... } ⇒ Name
Returns a new instance of Name.
58
59
60
61
62
63
|
# File 'lib/csl/style/names.rb', line 58
def initialize(attributes = {})
super(attributes)
children[:'name-part'] = []
yield self if block_given?
end
|
Instance Method Details
#all_names_as_sort_order! ⇒ Object
179
180
181
182
|
# File 'lib/csl/style/names.rb', line 179
def all_names_as_sort_order!
attributes[:'name-as-sort-order'] = 'all'
self
end
|
#all_names_as_sort_order? ⇒ Boolean
170
171
172
|
# File 'lib/csl/style/names.rb', line 170
def all_names_as_sort_order?
!!(attributes[:'name-as-sort-order'].to_s =~ /^all$/i)
end
|
#connector ⇒ Object
337
338
339
340
|
# File 'lib/csl/style/names.rb', line 337
def connector
c = attributes[:and]
c == 'symbol' ? '&' : c
end
|
#connector=(c) ⇒ Object
342
343
344
|
# File 'lib/csl/style/names.rb', line 342
def connector=(c)
attributes[:and] = c
end
|
#count? ⇒ Boolean
65
66
67
|
# File 'lib/csl/style/names.rb', line 65
def count?
attribute?(:form) && attributes[:form] == 'count'
end
|
#delimiter ⇒ String
Returns the delimiter between names.
147
148
149
|
# File 'lib/csl/style/names.rb', line 147
def delimiter
attributes[:delimiter] || ', '
end
|
#delimiter_always_precedes_et_al! ⇒ self
Also known as:
delimiter_precedes_et_al!
Set the :‘delimiter-precedes-et-al’ attribute to ‘always’.
207
208
209
210
|
# File 'lib/csl/style/names.rb', line 207
def delimiter_always_precedes_et_al!
attributes[:'delimiter-precedes-et-al'] = 'always'
self
end
|
#delimiter_always_precedes_et_al? ⇒ Boolean
Returns whether or not the delimmiter should always be inserted before et-al.
201
202
203
|
# File 'lib/csl/style/names.rb', line 201
def delimiter_always_precedes_et_al?
!!(attributes[:'delimiter-precedes-et-al'].to_s =~ /^always$/i)
end
|
#delimiter_always_precedes_last! ⇒ self
Also known as:
delimiter_precedes_last!
Set the :‘delimiter-precedes-last’ attribute to ‘always’.
285
286
287
288
|
# File 'lib/csl/style/names.rb', line 285
def delimiter_always_precedes_last!
attributes[:'delimiter-precedes-last'] = 'always'
self
end
|
#delimiter_always_precedes_last? ⇒ Boolean
Returns whether or not the should always be inserted between the penultimate and the last name.
279
280
281
|
# File 'lib/csl/style/names.rb', line 279
def delimiter_always_precedes_last?
!!(attributes[:'delimiter-precedes-last'].to_s =~ /^always$/i)
end
|
#delimiter_contextually_precedes_et_al! ⇒ self
Set the :‘delimiter-precedes-et-al’ attribute to ‘contextual’
238
239
240
241
|
# File 'lib/csl/style/names.rb', line 238
def delimiter_contextually_precedes_et_al!
attributes[:'delimiter-precedes-et-al'] = 'contextual'
self
end
|
#delimiter_contextually_precedes_et_al? ⇒ Boolean
Returns whether or not the delimtier should be inserted between before et-al depending on the number of names rendered.
231
232
233
234
|
# File 'lib/csl/style/names.rb', line 231
def delimiter_contextually_precedes_et_al?
return true unless attribute?[:'delimiter-precedes-et-al']
!!(attributes[:'delimiter-precedes-et-al'].to_s =~ /^contextual/i)
end
|
#delimiter_contextually_precedes_last! ⇒ self
Set the :‘delimiter-precedes-last’ attribute to ‘contextual’
315
316
317
318
|
# File 'lib/csl/style/names.rb', line 315
def delimiter_contextually_precedes_last!
attributes[:'delimiter-precedes-last'] = 'contextual'
self
end
|
#delimiter_contextually_precedes_last? ⇒ Boolean
Returns whether or not the should be inserted between the penultimate and the last name depending on the number of names.
308
309
310
311
|
# File 'lib/csl/style/names.rb', line 308
def delimiter_contextually_precedes_last?
return true unless attribute?(:'delimiter-precedes-last')
!!(attributes[:'delimiter-precedes-last'].to_s =~ /^contextual/i)
end
|
#delimiter_never_precedes_et_al! ⇒ self
Set the :‘delimiter-precedes-et-al’ attribute to ‘never’
223
224
225
226
|
# File 'lib/csl/style/names.rb', line 223
def delimiter_never_precedes_et_al!
attributes[:'delimiter-precedes-et-al'] = 'never'
self
end
|
#delimiter_never_precedes_et_al? ⇒ Boolean
Returns whether or not the delimiter should never be inserted before et-al.
217
218
219
|
# File 'lib/csl/style/names.rb', line 217
def delimiter_never_precedes_et_al?
!!(attributes[:'delimiter-precedes-et-al'].to_s =~ /^never$/i)
end
|
#delimiter_never_precedes_last! ⇒ self
Set the :‘delimiter-precedes-last’ attribute to ‘never’
301
302
303
304
|
# File 'lib/csl/style/names.rb', line 301
def delimiter_never_precedes_last!
attributes[:'delimiter-precedes-last'] = 'never'
self
end
|
#delimiter_never_precedes_last? ⇒ Boolean
Returns whether or not the should never be inserted between the penultimate and the last name.
295
296
297
|
# File 'lib/csl/style/names.rb', line 295
def delimiter_never_precedes_last?
!!(attributes[:'delimiter-precedes-last'].to_s =~ /^never$/i)
end
|
#delimiter_precedes_et_al?(names) ⇒ Boolean
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/csl/style/names.rb', line 184
def delimiter_precedes_et_al?(names)
names = names.length if names.respond_to?(:length)
case
when delimiter_never_precedes_et_al?
false
when delimiter_always_precedes_et_al?
true
when delimiter_precedes_et_al_after_inverted_name?
name_as_sort_order_at?(names.to_i)
else
names.to_i > 1
end
end
|
#delimiter_precedes_et_al_after_inverted_name! ⇒ Object
247
248
249
250
|
# File 'lib/csl/style/names.rb', line 247
def delimiter_precedes_et_al_after_inverted_name!
attributes[:'delimiter-precedes-et-al'] = 'after-inverted-name'
self
end
|
#delimiter_precedes_et_al_after_inverted_name? ⇒ Boolean
243
244
245
|
# File 'lib/csl/style/names.rb', line 243
def delimiter_precedes_et_al_after_inverted_name?
!!(attributes[:'delimiter-precedes-et-al'].to_s =~ /^after-inverted-name/i)
end
|
#delimiter_precedes_last?(names) ⇒ Boolean
Returns whether or not the delimiter will be inserted between the penultimate and the last name.
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
# File 'lib/csl/style/names.rb', line 255
def delimiter_precedes_last?(names)
names = names.length if names.respond_to?(:length)
case
when !attribute?(:and)
true
when delimiter_never_precedes_last?
false
when delimiter_always_precedes_last?
true
when delimiter_precedes_last_after_inverted_name?
if name_as_sort_order?
all_names_as_sort_order? || names.to_i == 2
else
false
end
else
names.to_i > 2
end
end
|
#delimiter_precedes_last_after_inverted_name! ⇒ Object
324
325
326
327
|
# File 'lib/csl/style/names.rb', line 324
def delimiter_precedes_last_after_inverted_name!
attributes[:'delimiter-precedes-last'] = 'after-inverted-name'
self
end
|
#delimiter_precedes_last_after_inverted_name? ⇒ Boolean
320
321
322
|
# File 'lib/csl/style/names.rb', line 320
def delimiter_precedes_last_after_inverted_name?
!!(attributes[:'delimiter-precedes-last'].to_s =~ /^after-inverted-name/i)
end
|
333
334
335
|
# File 'lib/csl/style/names.rb', line 333
def ellipsis
"#{delimiter}… "
end
|
#ellipsis? ⇒ Boolean
329
330
331
|
# File 'lib/csl/style/names.rb', line 329
def ellipsis?
attributes[:'et-al-use-last'].to_s =~ /^true$/
end
|
78
79
80
|
# File 'lib/csl/style/names.rb', line 78
def et_al
@et_al || parent && parent.et_al
end
|
#et_al=(et_al) ⇒ Object
82
83
84
|
# File 'lib/csl/style/names.rb', line 82
def et_al=(et_al)
@et_al = et_al
end
|
#first_name_as_sort_order! ⇒ Object
174
175
176
177
|
# File 'lib/csl/style/names.rb', line 174
def first_name_as_sort_order!
attributes[:'name-as-sort-order'] = 'first'
self
end
|
#first_name_as_sort_order? ⇒ Boolean
166
167
168
|
# File 'lib/csl/style/names.rb', line 166
def first_name_as_sort_order?
!!(attributes[:'name-as-sort-order'].to_s =~ /^first$/i)
end
|
#initialize_without_hyphen? ⇒ Boolean
73
74
75
76
|
# File 'lib/csl/style/names.rb', line 73
def initialize_without_hyphen?
!root? && root.respond_to?(:initialize_without_hyphen?) &&
root.initialize_without_hyphen?
end
|
#name_as_sort_order ⇒ Object
Also known as:
sort_order
160
161
162
|
# File 'lib/csl/style/names.rb', line 160
def name_as_sort_order
attributes[:'name-as-sort-order'].to_s
end
|
#name_as_sort_order? ⇒ Boolean
151
152
153
|
# File 'lib/csl/style/names.rb', line 151
def name_as_sort_order?
attribute?(:'name-as-sort-order')
end
|
#name_as_sort_order_at?(position) ⇒ Boolean
155
156
157
158
|
# File 'lib/csl/style/names.rb', line 155
def name_as_sort_order_at?(position)
return false unless name_as_sort_order?
all_names_as_sort_order? || position == 1 && first_name_as_sort_order?
end
|
#name_options ⇒ Object
69
70
71
|
# File 'lib/csl/style/names.rb', line 69
def name_options
attributes_for :form, :initialize, :'initialize-with', :'sort-separator'
end
|
#sort_separator ⇒ String
Returns the delimiter between family and given names in sort order.
142
143
144
|
# File 'lib/csl/style/names.rb', line 142
def sort_separator
attributes[:'sort-separator'] || ', '
end
|
#truncate(names, subsequent = false) ⇒ Array
Returns the truncated list of names.
98
99
100
101
102
|
# File 'lib/csl/style/names.rb', line 98
def truncate(names, subsequent = false)
count = truncate_at(subsequent)
count = names.length if count.nil?
names.take count.to_i
end
|
#truncate?(names, subsequent = false) ⇒ Boolean
Returns whether or not the list should be truncated.
88
89
90
91
92
93
94
|
# File 'lib/csl/style/names.rb', line 88
def truncate?(names, subsequent = false)
names = names.length if names.respond_to?(:length)
limit = truncate_when(subsequent)
count = truncate_at(subsequent)
!count.nil? && !limit.nil? && names.to_i >= limit.to_i
end
|
#truncate_at(subsequent = false) ⇒ Object
112
113
114
115
116
117
118
|
# File 'lib/csl/style/names.rb', line 112
def truncate_at(subsequent = false)
if subsequent && attribute?(:'et-al-subsequent-use-first')
attributes.fetch(:'et-al-subsequent-use-first')
else
attributes.fetch(:'et-al-use-first')
end
end
|
#truncate_at!(at) ⇒ Object
120
121
122
123
|
# File 'lib/csl/style/names.rb', line 120
def truncate_at!(at)
attributes[:'et-al-use-first'] = at.to_i
self
end
|
#truncate_subsequent_at!(at) ⇒ Object
130
131
132
133
|
# File 'lib/csl/style/names.rb', line 130
def truncate_subsequent_at!(at)
attributes[:'et-al-subsequent-use-first'] = at.to_i
self
end
|
#truncate_subsequent_when!(pos) ⇒ Object
135
136
137
138
|
# File 'lib/csl/style/names.rb', line 135
def truncate_subsequent_when!(pos)
attributes[:'et-al-subsequent-min'] = pos.to_i
self
end
|
#truncate_when(subsequent = false) ⇒ Object
104
105
106
107
108
109
110
|
# File 'lib/csl/style/names.rb', line 104
def truncate_when(subsequent = false)
if subsequent && attribute?(:'et-al-subsequent-min')
attributes[:'et-al-subsequent-min']
else
attributes[:'et-al-min']
end
end
|
#truncate_when!(pos) ⇒ Object
125
126
127
128
|
# File 'lib/csl/style/names.rb', line 125
def truncate_when!(pos)
attributes[:'et-al-min'] = pos.to_i
self
end
|