Class: FormResourceDecorator

Inherits:
Object
  • Object
show all
Defined in:
app/decorators/form_resource_decorator.rb

Constant Summary collapse

SKIPPED_ROLES =
["DISTRIBUTOR", "FUNDER", "HOSTING_INSTITUTION", "REGISTRATION_AGENCY", "REGISTRATION_AUTHORITY", "RESEARCH GROUP"].freeze
PPPL_FUNDER_NAME =
"United States Department of Energy"
PPPL_FUNDER_ROR =
"https://ror.org/01bj3aw27"
PPPL_FUNDER_AWARD_NUMBER =
"DE-AC02-09CH11466"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work, current_user) ⇒ FormResourceDecorator

Returns a new instance of FormResourceDecorator.



10
11
12
13
14
# File 'app/decorators/form_resource_decorator.rb', line 10

def initialize(work, current_user)
  @resource = work.resource
  @work = work
  @current_user = current_user
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



3
4
5
# File 'app/decorators/form_resource_decorator.rb', line 3

def current_user
  @current_user
end

#resourceObject (readonly)

Returns the value of attribute resource.



3
4
5
# File 'app/decorators/form_resource_decorator.rb', line 3

def resource
  @resource
end

#workObject (readonly)

Returns the value of attribute work.



3
4
5
# File 'app/decorators/form_resource_decorator.rb', line 3

def work
  @work
end

Instance Method Details

#contributor_typesObject



29
30
31
32
# File 'app/decorators/form_resource_decorator.rb', line 29

def contributor_types
  @contributor_types ||= Datacite::Mapping::ContributorType.to_a.reject { |role| SKIPPED_ROLES.include? role.key.to_s }
  @contributor_types
end

#creatorsObject



38
39
40
# File 'app/decorators/form_resource_decorator.rb', line 38

def creators
  item_or_nil_array(resource.creators)
end

#doi_mutable?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
# File 'app/decorators/form_resource_decorator.rb', line 46

def doi_mutable?
  return true unless !@work.nil? && @work.persisted?

  !@work.approved?
end

#fundersObject



16
17
18
19
20
21
22
23
# File 'app/decorators/form_resource_decorator.rb', line 16

def funders # @funders probably null for some reason
  @funders ||= begin
                 empty_row = if pppl? && resource.funders.empty?
                               PDCMetadata::Funder.new(PPPL_FUNDER_ROR, PPPL_FUNDER_NAME, PPPL_FUNDER_AWARD_NUMBER, nil)
                             end
                 resource.funders + [empty_row]
               end
end

#individual_contributorsObject



25
26
27
# File 'app/decorators/form_resource_decorator.rb', line 25

def individual_contributors
  item_or_nil_array(resource.individual_contributors)
end

#organizational_contributorsObject



42
43
44
# File 'app/decorators/form_resource_decorator.rb', line 42

def organizational_contributors
  resource.organizational_contributors + [nil]
end


34
35
36
# File 'app/decorators/form_resource_decorator.rb', line 34

def related_objects
  item_or_nil_array(resource.related_objects)
end