Class: Accessionable::Base

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

Overview

Base class to control generating XML for accessioning with the ENA or EGA

See Also:

Direct Known Subclasses

Dac, Policy, Sample, Study, Submission

Defined Under Namespace

Classes: Tag

Constant Summary collapse

InvalidData =
Class.new(AccessionService::AccessionServiceError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(accession_number) ⇒ Base

Returns a new instance of Base.


6
7
8
9
10
11
12
# File 'app/models/accessionable/base.rb', line 6

def initialize(accession_number)
  @accession_number = accession_number

  time_now = Time.zone.now
  @date = time_now.strftime('%Y-%m-%dT%H:%M:%SZ')
  @date_short = time_now.strftime('%Y-%m-%d')
end

Instance Attribute Details

#accession_numberObject (readonly)

Returns the value of attribute accession_number


5
6
7
# File 'app/models/accessionable/base.rb', line 5

def accession_number
  @accession_number
end

#dateObject (readonly)

Returns the value of attribute date


5
6
7
# File 'app/models/accessionable/base.rb', line 5

def date
  @date
end

#date_shortObject (readonly)

Returns the value of attribute date_short


5
6
7
# File 'app/models/accessionable/base.rb', line 5

def date_short
  @date_short
end

#nameObject (readonly)

Returns the value of attribute name


5
6
7
# File 'app/models/accessionable/base.rb', line 5

def name
  @name
end

Instance Method Details

#accessionable_idObject

Raises:

  • (NotImplementError)

56
57
58
# File 'app/models/accessionable/base.rb', line 56

def accessionable_id
  raise NotImplementError, 'abstract method'
end

#add_updated_event(user, classname, eventable) ⇒ Object


65
66
67
68
69
70
71
72
# File 'app/models/accessionable/base.rb', line 65

def add_updated_event(user, classname, eventable)
  eventable.events.create(
    created_by: user.,
    message: "#{classname} #{eventable.id} accession data has been updated by user #{user.}",
    content: 'accession number regenerated',
    of_interest_to: 'administrators'
  )
end

#aliasObject


31
32
33
# File 'app/models/accessionable/base.rb', line 31

def alias
  "#{name.gsub(/[^a-z\d]/i, '_')}-sc-#{accessionable_id}"
end

#center_nameObject


22
23
24
# File 'app/models/accessionable/base.rb', line 22

def center_name
  AccessionService::CenterName
end

#errorsObject


14
15
16
# File 'app/models/accessionable/base.rb', line 14

def errors
  []
end

#extract_accession_number(xmldoc) ⇒ Object


39
40
41
42
# File 'app/models/accessionable/base.rb', line 39

def extract_accession_number(xmldoc)
  element = xmldoc.root.elements["/RECEIPT/#{schema_type.upcase}"]
  accession_number = element && element.attributes['accession']
end

#extract_array_express_accession_number(xmldoc) ⇒ Object


44
45
46
47
# File 'app/models/accessionable/base.rb', line 44

def extract_array_express_accession_number(xmldoc)
  element = xmldoc.root.elements["/RECEIPT/#{schema_type.upcase}/EXT_ID[@type='ArrayExpress']"]
  accession_number = element && element.attributes['accession']
end

#file_nameObject


35
36
37
# File 'app/models/accessionable/base.rb', line 35

def file_name
  "#{self.alias}-#{date}.#{schema_type}.xml"
end

#label_scopeObject


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

def label_scope
  @label_scope ||= "metadata.#{self.class.name.split("::").last.downcase}.metadata"
end

#released?Boolean

Returns:

  • (Boolean)

60
61
62
63
# File 'app/models/accessionable/base.rb', line 60

def released?
  # Return false by default. Overidden by sample.
  false
end

#schema_typeObject


26
27
28
29
# File 'app/models/accessionable/base.rb', line 26

def schema_type
  # raise NotImplementedError, "abstract method"
  self.class.name.split('::').last.downcase
end

#update_accession_number!(_user, _accession_number) ⇒ Object

Raises:

  • (NotImplementedError)

49
50
51
# File 'app/models/accessionable/base.rb', line 49

def update_accession_number!(_user, _accession_number)
  raise NotImplementedError, 'abstract method'
end

#update_array_express_accession_number!(accession_number) ⇒ Object


53
54
# File 'app/models/accessionable/base.rb', line 53

def update_array_express_accession_number!(accession_number)
end

#xmlObject

Raises:

  • (NotImplementedError)

18
19
20
# File 'app/models/accessionable/base.rb', line 18

def xml
  raise NotImplementedError, 'abstract method'
end