Class: Accessionable::Study

Inherits:
Base
  • Object
show all
Defined in:
app/models/accessionable/study.rb

Overview

rubocop:todo Style/Documentation

Constant Summary

Constants inherited from Base

Base::InvalidData

Instance Attribute Summary collapse

Attributes inherited from Base

#accession_number, #date, #date_short, #name

Instance Method Summary collapse

Methods inherited from Base

#add_updated_event, #alias, #center_name, #extract_accession_number, #extract_array_express_accession_number, #file_name, #label_scope, #released?, #schema_type

Constructor Details

#initialize(study) ⇒ Study

Returns a new instance of Study.


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/accessionable/study.rb', line 11

def initialize(study)
  @study = study
  data = {}

  study_title = study..study_study_title
  @name = study_title.blank? ? '' : study_title.gsub(/[^a-z\d]/i, '_')

  study_type = study..study_type.name
  @existing_study_type = study_type # the study type if validated is exactly the one submission need

  @study_title = @name
  @center_study_name = @study_title

  pid = study..study_project_id
  @study_id = pid.presence || '0'

  study_abstract = study..study_abstract
  @study_abstract = study_abstract if study_abstract.present?

  study_desc = study..study_description
  @description = study_desc if study_desc.present?

  @tags = []
  @tags << Tag.new(label_scope, 'ArrayExpress', nil) if study.for_array_express?
  super(study..study_ebi_accession_number)
end

Instance Attribute Details

#center_study_nameObject (readonly)

Returns the value of attribute center_study_name


9
10
11
# File 'app/models/accessionable/study.rb', line 9

def center_study_name
  @center_study_name
end

#descriptionObject (readonly)

Returns the value of attribute description


9
10
11
# File 'app/models/accessionable/study.rb', line 9

def description
  @description
end

#existing_study_typeObject (readonly)

Returns the value of attribute existing_study_type


9
10
11
# File 'app/models/accessionable/study.rb', line 9

def existing_study_type
  @existing_study_type
end

#study_abstractObject (readonly)

Returns the value of attribute study_abstract


9
10
11
# File 'app/models/accessionable/study.rb', line 9

def study_abstract
  @study_abstract
end

#study_titleObject (readonly)

Returns the value of attribute study_title


9
10
11
# File 'app/models/accessionable/study.rb', line 9

def study_title
  @study_title
end

#tagsObject (readonly)

Returns the value of attribute tags


9
10
11
# File 'app/models/accessionable/study.rb', line 9

def tags
  @tags
end

Instance Method Details

#accessionable_idObject


74
75
76
# File 'app/models/accessionable/study.rb', line 74

def accessionable_id
  @study.id
end

#errorsObject


38
39
40
# File 'app/models/accessionable/study.rb', line 38

def errors
  error_list = []
end

#protect?(service) ⇒ Boolean

Returns:

  • (Boolean)

78
79
80
# File 'app/models/accessionable/study.rb', line 78

def protect?(service)
  service.study_visibility(@study) == AccessionService::Protect
end

#update_accession_number!(user, accession_number) ⇒ Object


82
83
84
85
86
87
# File 'app/models/accessionable/study.rb', line 82

def update_accession_number!(user, accession_number)
  @accession_number = accession_number
  add_updated_event(user, "Study #{@study.id}", @study) if @accession_number
  @study..study_ebi_accession_number = accession_number
  @study.save!
end

#update_array_express_accession_number!(number) ⇒ Object


89
90
91
92
# File 'app/models/accessionable/study.rb', line 89

def update_array_express_accession_number!(number)
  @study..array_express_accession_number = number
  @study.save!
end

#xmlObject


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/accessionable/study.rb', line 42

def xml
  xml = Builder::XmlMarkup.new
  xml.instruct!
  xml.STUDY_SET('xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance') do
    xml.STUDY(alias: self.alias, accession: accession_number) do
      xml.DESCRIPTOR do
        xml.STUDY_TITLE         study_title
        xml.STUDY_DESCRIPTION   description
        xml.CENTER_PROJECT_NAME center_study_name
        xml.CENTER_NAME         center_name
        xml.STUDY_ABSTRACT      study_abstract

        xml.PROJECT_ID(accessionable_id || '0')
        study_type = existing_study_type
        if StudyType.include?(study_type)
          xml.STUDY_TYPE(existing_study_type: study_type)
        else
          xml.STUDY_TYPE(existing_study_type: ::Study::Other_type, new_study_type: study_type)
        end
      end
      xml.STUDY_ATTRIBUTES do
        tags.each do |tag|
          xml.STUDY_ATTRIBUTE do
            tag.build(xml)
          end
        end
      end if tags.present?
    end
  end
  xml.target!
end