Class: CSL::Style::Name
Instance Attribute Summary
Attributes inherited from Node
Attributes included from Treelike
Instance Method Summary collapse
- #all_names_as_sort_order? ⇒ Boolean
- #connector ⇒ Object
-
#delimiter ⇒ String
The delimiter between names.
-
#delimiter_always_precedes_last! ⇒ self
(also: #delimiter_precedes_last!)
Set the :‘delimiter-precedes-last’ attribute to ‘always’.
-
#delimiter_always_precedes_last? ⇒ Boolean
Whether or not the should always be inserted between the penultimate and the last name.
-
#delimiter_contextually_precedes_last! ⇒ self
Set the :‘delimiter-precedes-last’ attribute to ‘contextual’.
-
#delimiter_contextually_precedes_last? ⇒ Boolean
Whether or not the should be inserted between the penultimate and the last name depending on the number of names.
-
#delimiter_never_precedes_last! ⇒ self
Set the :‘delimiter-precedes-last’ attribute to ‘never’.
-
#delimiter_never_precedes_last? ⇒ Boolean
Whether or not the should never be inserted between the penultimate and the last name.
-
#delimiter_precedes_last?(names) ⇒ Boolean
Whether or not the delimiter will be inserted between the penultimate and the last name.
- #delimiter_precedes_last_after_inverted_name! ⇒ Object
- #delimiter_precedes_last_after_inverted_name? ⇒ Boolean
- #ellipsis? ⇒ Boolean
- #et_al ⇒ Object
- #first_name_as_sort_order? ⇒ Boolean
-
#initialize(attributes = {}) {|_self| ... } ⇒ Name
constructor
A new instance of Name.
- #initialize? ⇒ Boolean
- #name_as_sort_order ⇒ Object (also: #sort_order)
- #name_as_sort_order? ⇒ Boolean
-
#sort_separator ⇒ String
The delimiter between family and given names in sort order.
-
#truncate(names, subsequent = false) ⇒ Array
The truncated list of names.
-
#truncate?(names, subsequent = false) ⇒ Boolean
Whether or not the should be truncate.
- #truncate_at(subsequent = false) ⇒ Object
- #truncate_when(subsequent = false) ⇒ Object
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?, #formatting_options, #has_attributes?, #has_default_attributes?, #has_language?, hide_default_attributes!, hide_default_attributes?, #initialize_copy, #inspect, #match?, match?, matches?, parse, parse!, #save_to, show_default_attributes!, #tags, #textnode?, types
Methods included from PrettyPrinter
Methods included from Treelike
#<<, #add_child, #add_children, #ancestors, #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.
46 47 48 49 50 51 |
# File 'lib/csl/style/names.rb', line 46 def initialize(attributes = {}) super(attributes) children[:'name-part'] = [] yield self if block_given? end |
Instance Method Details
#all_names_as_sort_order? ⇒ Boolean
121 122 123 |
# File 'lib/csl/style/names.rb', line 121 def all_names_as_sort_order? attributes[:'name-as-sort-order'].to_s =~ /^all$/i end |
#connector ⇒ Object
206 207 208 209 |
# File 'lib/csl/style/names.rb', line 206 def connector c = attributes[:and] c == 'symbol' ? '&' : c end |
#delimiter ⇒ String
Returns the delimiter between names.
103 104 105 |
# File 'lib/csl/style/names.rb', line 103 def delimiter attributes[:delimiter].to_s end |
#delimiter_always_precedes_last! ⇒ self Also known as: delimiter_precedes_last!
Set the :‘delimiter-precedes-last’ attribute to ‘always’.
159 160 161 162 |
# File 'lib/csl/style/names.rb', line 159 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.
153 154 155 |
# File 'lib/csl/style/names.rb', line 153 def delimiter_always_precedes_last? !!(attributes[:'delimiter-precedes-last'].to_s =~ /^always$/i) end |
#delimiter_contextually_precedes_last! ⇒ self
Set the :‘delimiter-precedes-last’ attribute to ‘contextual’
188 189 190 191 |
# File 'lib/csl/style/names.rb', line 188 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.
182 183 184 |
# File 'lib/csl/style/names.rb', line 182 def delimiter_contextually_precedes_last? !!(attributes[:'delimiter-precedes-last'].to_s =~ /^contextual/i) end |
#delimiter_never_precedes_last! ⇒ self
Set the :‘delimiter-precedes-last’ attribute to ‘never’
175 176 177 178 |
# File 'lib/csl/style/names.rb', line 175 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.
169 170 171 |
# File 'lib/csl/style/names.rb', line 169 def delimiter_never_precedes_last? !!(attributes[:'delimiter-precedes-last'].to_s =~ /^never$/i) end |
#delimiter_precedes_last?(names) ⇒ Boolean
Returns whether or not the delimiter will be inserted between the penultimate and the last name.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/csl/style/names.rb', line 129 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_precedeces_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
197 198 199 200 |
# File 'lib/csl/style/names.rb', line 197 def delimiter_precedes_last_after_inverted_name! attributes[:'delimiter-precedes-last'] = 'after-inverted-name' self end |
#delimiter_precedes_last_after_inverted_name? ⇒ Boolean
193 194 195 |
# File 'lib/csl/style/names.rb', line 193 def delimiter_precedes_last_after_inverted_name? !!(attributes[:'delimiter-precedes-last'].to_s =~ /^after-inverted-name/i) end |
#ellipsis? ⇒ Boolean
202 203 204 |
# File 'lib/csl/style/names.rb', line 202 def ellipsis? attributes[:'et-al-use-last'].to_s =~ /^true$/ end |
#et_al ⇒ Object
58 59 60 |
# File 'lib/csl/style/names.rb', line 58 def et_al parent && parent.et_al end |
#first_name_as_sort_order? ⇒ Boolean
117 118 119 |
# File 'lib/csl/style/names.rb', line 117 def first_name_as_sort_order? attributes[:'name-as-sort-order'].to_s =~ /^first$/i end |
#initialize? ⇒ Boolean
54 55 56 |
# File 'lib/csl/style/names.rb', line 54 def initialize? attributes[:initialize].to_s !~ /^false$/i end |
#name_as_sort_order ⇒ Object Also known as: sort_order
111 112 113 |
# File 'lib/csl/style/names.rb', line 111 def name_as_sort_order attributes[:'name-as-sort-order'].to_s end |
#name_as_sort_order? ⇒ Boolean
107 108 109 |
# File 'lib/csl/style/names.rb', line 107 def name_as_sort_order? attribute?(:'name-as-sort-order') end |
#sort_separator ⇒ String
Returns the delimiter between family and given names in sort order.
98 99 100 |
# File 'lib/csl/style/names.rb', line 98 def sort_separator attributes[:'sort-separator'].to_s end |
#truncate(names, subsequent = false) ⇒ Array
Returns the truncated list of names.
73 74 75 76 77 78 |
# File 'lib/csl/style/names.rb', line 73 def truncate(names, subsequent = false) limit = truncate_at(subsequent) return names if limit.zero? names.take limit end |
#truncate?(names, subsequent = false) ⇒ Boolean
Returns whether or not the should be truncate.
64 65 66 67 68 69 |
# File 'lib/csl/style/names.rb', line 64 def truncate?(names, subsequent = false) names = names.length if names.respond_to?(:length) limit = truncate_when(subsequent) !limit.zero? && names.to_i >= limit end |
#truncate_at(subsequent = false) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/csl/style/names.rb', line 88 def truncate_at(subsequent = false) if subsequent && attribute?(:'et-al-subsequent-use-first') attribute[:'et-al-subsequent-use-first'].to_i else attribute[:'et-al-use-first'].to_i end end |
#truncate_when(subsequent = false) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/csl/style/names.rb', line 80 def truncate_when(subsequent = false) if subsequent && attribute?(:'et-al-subsequent-min') attribute[:'et-al-subsequent-min'].to_i else attribute[:'et-al-min'].to_i end end |