Class: Scholar::Utilities::ContributorList

Inherits:
Object
  • Object
show all
Defined in:
lib/scholar/utilities/contributor_list.rb

Overview

A list of Contributors.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contributors, role = :nonauthor) ⇒ ContributorList

Create a list of Contributors.

Attributes

  • contributors - An Array of Contributors or an Array of Hashes.

  • role - Either :author: or :nonauthor.

Examples

Scholar::Utilities::ContributorList.new([
  {
    :first => "Douglas",
    :last => "Adams"
  },
  {
    :first => "Eion",
    :last => "Colfer"
  }
])


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/scholar/utilities/contributor_list.rb', line 34

def initialize(contributors, role = :nonauthor)
  @names = ""

  contributors.each do |c|
    if c.is_a?(Hash)
      contributors[contributors.index(c)] = Contributor.new(c)
    end
  end

  contributors.each do |c|
    if contributors.index(c) == 0 && role == :author
      c.reorder!(:last)
    else
      c.reorder!(:first)
    end

    @names << c.name

    unless contributors.last == c
      @names << ", "
    end
  end

  @contributors = contributors
  @role = role

  return self
end

Instance Attribute Details

#contributorsObject (readonly)

An Array of Contributors.



10
11
12
# File 'lib/scholar/utilities/contributor_list.rb', line 10

def contributors
  @contributors
end

#namesObject (readonly)

The names in MLA format.



13
14
15
# File 'lib/scholar/utilities/contributor_list.rb', line 13

def names
  @names
end