Class: BibTeX::Name

Inherits:
Struct
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/bibtex/names.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Name

Returns a new instance of Name.



109
110
111
112
113
# File 'lib/bibtex/names.rb', line 109

def initialize(attributes = {})
  attributes.each do |key,value|
    send("#{key}=", value) if respond_to?(key)
  end
end

Instance Attribute Details

#firstObject Also known as: given

Returns the value of attribute first

Returns:

  • (Object)

    the current value of first



91
92
93
# File 'lib/bibtex/names.rb', line 91

def first
  @first
end

#lastObject Also known as: family

Returns the value of attribute last

Returns:

  • (Object)

    the current value of last



91
92
93
# File 'lib/bibtex/names.rb', line 91

def last
  @last
end

#prefixObject Also known as: von

Returns the value of attribute prefix

Returns:

  • (Object)

    the current value of prefix



91
92
93
# File 'lib/bibtex/names.rb', line 91

def prefix
  @prefix
end

#suffixObject Also known as: jr

Returns the value of attribute suffix

Returns:

  • (Object)

    the current value of suffix



91
92
93
# File 'lib/bibtex/names.rb', line 91

def suffix
  @suffix
end

Class Method Details

.looks_like?(thing) ⇒ Boolean

Returns true if thing looks like a name. Actually converts thing to a string and tries to parse it.

Returns:

  • (Boolean)


104
105
106
# File 'lib/bibtex/names.rb', line 104

def looks_like?(thing)
  thing.respond_to?(:to_s) && [Name.new.parse(string)].flatten.compact.empty?
end

.parse(string) ⇒ Object



98
99
100
# File 'lib/bibtex/names.rb', line 98

def parse(string)
  [NameParser.new.parse(string)].flatten[0]
end

Instance Method Details

#<=>(other) ⇒ Object



135
136
137
# File 'lib/bibtex/names.rb', line 135

def <=>(other)
  other.is_a?(Name) ? [last, prefix, first, suffix].compact.join(' ') <=> [other.last, other.prefix, other.first, other.suffix].compact.join(' ') : super
end

#blank?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/bibtex/names.rb', line 119

def blank?
  to_a.compact.empty?
end

#display_orderObject Also known as: display



123
124
125
# File 'lib/bibtex/names.rb', line 123

def display_order
  [prefix, last, first, suffix].compact.join(' ')
end

#initalize_copy(other) ⇒ Object



115
116
117
# File 'lib/bibtex/names.rb', line 115

def initalize_copy(other)
  each_pair { |k,v| self[k] = v }
end

#sort_orderObject Also known as: to_s



129
130
131
# File 'lib/bibtex/names.rb', line 129

def sort_order
  [[prefix,last].compact.join(' '), suffix, first].compact.join(', ')
end

#to_citeproc(options = {}) ⇒ Object



152
153
154
155
156
157
158
159
# File 'lib/bibtex/names.rb', line 152

def to_citeproc(options = {})
  hash = {}
  hash['family'] = family unless family.nil?
  hash['given'] = given unless given.nil?
  hash['suffix'] = suffix unless suffix.nil?
  hash['dropping-particle'] = prefix unless prefix.nil?
  hash
end

#to_hashObject



139
140
141
# File 'lib/bibtex/names.rb', line 139

def to_hash
  Hash[each_pair.to_a]
end