Class: CSL::Style::Name

Inherits:
Node show all
Defined in:
lib/csl/style/names.rb

Instance Attribute Summary

Attributes inherited from Node

#attributes

Attributes included from Treelike

#children, #nodename, #parent

Instance Method Summary collapse

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

#pretty_print, #tags, #to_xml

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.

Yields:

  • (_self)

Yield Parameters:



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

Returns:

  • (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

#connectorObject



206
207
208
209
# File 'lib/csl/style/names.rb', line 206

def connector
  c = attributes[:and]
  c == 'symbol' ? '&' : c
end

#delimiterString

Returns the delimiter between names.

Returns:

  • (String)

    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’.

Returns:

  • (self)

    self



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.

Returns:

  • (Boolean)

    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’

Returns:

  • (self)

    self



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.

Returns:

  • (Boolean)

    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’

Returns:

  • (self)

    self



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.

Returns:

  • (Boolean)

    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.

Parameters:

  • names (#to_i, Enumerable)

    the list of names (or its length)

Returns:

  • (Boolean)

    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

Returns:

  • (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

Returns:

  • (Boolean)


202
203
204
# File 'lib/csl/style/names.rb', line 202

def ellipsis?
  attributes[:'et-al-use-last'].to_s =~ /^true$/
end

#et_alObject



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

Returns:

  • (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

Returns:

  • (Boolean)


54
55
56
# File 'lib/csl/style/names.rb', line 54

def initialize?
  attributes[:initialize].to_s !~ /^false$/i
end

#name_as_sort_orderObject 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

Returns:

  • (Boolean)


107
108
109
# File 'lib/csl/style/names.rb', line 107

def name_as_sort_order?
  attribute?(:'name-as-sort-order')
end

#sort_separatorString

Returns the delimiter between family and given names in sort order.

Returns:

  • (String)

    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.

Parameters:

  • names (Enumerable)

Returns:

  • (Array)

    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.

Parameters:

  • names (#to_i, Enumerable)

    the list of names (or its length)

Returns:

  • (Boolean)

    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