Class: Scholar::Utilities::Contributor
- Inherits:
-
Object
- Object
- Scholar::Utilities::Contributor
- Defined in:
- lib/scholar/utilities/contributor.rb
Overview
A person associated with a work.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
The data associated with the person.
-
#name ⇒ Object
readonly
The name in the correct format.
Instance Method Summary collapse
-
#initialize(data, order = :first) ⇒ Contributor
constructor
Create a Contributor.
-
#reorder!(order) ⇒ Object
Reorders the name of the Contributor with the given order.
Constructor Details
#initialize(data, order = :first) ⇒ Contributor
Create a Contributor.
Attributes
-
data
- The data associated with the Contributor. -
order
- Last-name first (:last
) or first-name first (:first
).
Options
-
:first
- The name of the Contributor. -
:middle
- The middle name of the Contributor. Will be shortened to an initial. -
:last
- The surname of the Contributor. -
:suffix
- The suffix of the Contributor (PhD, Esq, etc).
Examples
Scholar::Utilities::Contributor.new({
:first => "Douglas",
:last => "Adams"
})
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/scholar/utilities/contributor.rb', line 36 def initialize(data, order = :first) if data.is_a?(String) data = hash!(data) data[:role] = :author end data.delete_if {|k, v| v.nil? || v.empty? } @order = order @attributes = order!(data) @name = name!(@attributes) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
The data associated with the person.
10 11 12 |
# File 'lib/scholar/utilities/contributor.rb', line 10 def attributes @attributes end |
#name ⇒ Object (readonly)
The name in the correct format.
13 14 15 |
# File 'lib/scholar/utilities/contributor.rb', line 13 def name @name end |
Instance Method Details
#reorder!(order) ⇒ Object
Reorders the name of the Contributor with the given order.
Attributes
-
order
- Either:first
or:last
name first.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/scholar/utilities/contributor.rb', line 56 def reorder!(order) @order = order @attributes = order!(@attributes, order) @name = name!(@attributes) if @name[-2, 2] == ".," # Fix this. @name = @name[0..-3] end self end |