Class: BibTeX::Name
- Inherits:
-
Struct
- Object
- Struct
- BibTeX::Name
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/bibtex/names.rb
Instance Attribute Summary collapse
-
#first ⇒ Object
(also: #given)
Returns the value of attribute first.
-
#last ⇒ Object
(also: #family)
Returns the value of attribute last.
-
#prefix ⇒ Object
(also: #von)
Returns the value of attribute prefix.
-
#suffix ⇒ Object
(also: #jr)
Returns the value of attribute suffix.
Class Method Summary collapse
-
.looks_like?(thing) ⇒ Boolean
Returns true if thing looks like a name.
- .parse(string) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #blank? ⇒ Boolean
- #display_order ⇒ Object (also: #display)
- #initalize_copy(other) ⇒ Object
-
#initialize(attributes = {}) ⇒ Name
constructor
A new instance of Name.
- #sort_order ⇒ Object (also: #to_s)
- #to_citeproc(options = {}) ⇒ Object
- #to_hash ⇒ Object
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
#first ⇒ Object Also known as: given
Returns the value of attribute first
91 92 93 |
# File 'lib/bibtex/names.rb', line 91 def first @first end |
#last ⇒ Object Also known as: family
Returns the value of attribute last
91 92 93 |
# File 'lib/bibtex/names.rb', line 91 def last @last end |
#prefix ⇒ Object Also known as: von
Returns the value of attribute prefix
91 92 93 |
# File 'lib/bibtex/names.rb', line 91 def prefix @prefix end |
#suffix ⇒ Object Also known as: jr
Returns the value of attribute 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.
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
119 120 121 |
# File 'lib/bibtex/names.rb', line 119 def blank? to_a.compact.empty? end |
#display_order ⇒ Object 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_order ⇒ Object 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( = {}) 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_hash ⇒ Object
139 140 141 |
# File 'lib/bibtex/names.rb', line 139 def to_hash Hash[each_pair.to_a] end |