Class: Accessionable::Base

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

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


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

def initialize(accession_number)
  @accession_number = accession_number

  time_now = Time.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


3
4
5
# File 'app/models/accessionable/base.rb', line 3

def accession_number
  @accession_number
end

#dateObject (readonly)

Returns the value of attribute date


3
4
5
# File 'app/models/accessionable/base.rb', line 3

def date
  @date
end

#date_shortObject (readonly)

Returns the value of attribute date_short


3
4
5
# File 'app/models/accessionable/base.rb', line 3

def date_short
  @date_short
end

#nameObject (readonly)

Returns the value of attribute name


3
4
5
# File 'app/models/accessionable/base.rb', line 3

def name
  @name
end

Instance Method Details

#accessionable_idObject

Raises:

  • (NotImplementError)

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

def accessionable_id
  raise NotImplementError, 'abstract method'
end

#add_updated_event(user, classname, eventable) ⇒ Object


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

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


29
30
31
# File 'app/models/accessionable/base.rb', line 29

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

#center_nameObject


20
21
22
# File 'app/models/accessionable/base.rb', line 20

def center_name
  AccessionService::CenterName
end

#errorsObject


12
13
14
# File 'app/models/accessionable/base.rb', line 12

def errors
  []
end

#extract_accession_number(xmldoc) ⇒ Object


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

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


42
43
44
45
# File 'app/models/accessionable/base.rb', line 42

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


33
34
35
# File 'app/models/accessionable/base.rb', line 33

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

#label_scopeObject


72
73
74
# File 'app/models/accessionable/base.rb', line 72

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

#released?Boolean

Returns:

  • (Boolean)

58
59
60
61
# File 'app/models/accessionable/base.rb', line 58

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

#schema_typeObject


24
25
26
27
# File 'app/models/accessionable/base.rb', line 24

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

#update_accession_number!(_user, _accession_number) ⇒ Object

Raises:

  • (NotImplementedError)

47
48
49
# File 'app/models/accessionable/base.rb', line 47

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

#update_array_express_accession_number!(accession_number) ⇒ Object


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

def update_array_express_accession_number!(accession_number)
end

#xmlObject

Raises:

  • (NotImplementedError)

16
17
18
# File 'app/models/accessionable/base.rb', line 16

def xml
  raise NotImplementedError, 'abstract method'
end