Module: Accession::Accessionable

Included in:
Sample, Submission
Defined in:
lib/accession/accessionable.rb

Overview

Standard methods used by things that can be accessioned e.g sample

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ebi_aliasObject (readonly)

Returns the value of attribute ebi_alias.



5
6
7
# File 'lib/accession/accessionable.rb', line 5

def ebi_alias
  @ebi_alias
end

Instance Method Details

#build_xml(xml) ⇒ Object

Including classes models must implement this method to define their XML content. Example: def build_xml(xml) xml.sample_tag 'Sample content' end

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/accession/accessionable.rb', line 28

def build_xml(xml)
  raise NotImplementedError, "#{self.class} must implement the build_xml(xml) method"
end

#dateObject



11
12
13
# File 'lib/accession/accessionable.rb', line 11

def date
  @date ||= Time.now.utc.iso8601
end

#ebi_alias_datestampedObject



15
16
17
# File 'lib/accession/accessionable.rb', line 15

def ebi_alias_datestamped
  "#{ebi_alias}-#{date}"
end

#filenameObject



19
20
21
# File 'lib/accession/accessionable.rb', line 19

def filename
  @filename ||= clean_path("#{ebi_alias_datestamped}.#{schema_type}.xml")
end

#schema_typeObject



7
8
9
# File 'lib/accession/accessionable.rb', line 7

def schema_type
  @schema_type ||= self.class.to_s.demodulize.downcase
end

#to_fileTempfile

Creates a Tempfile containing the XML representation of the accessionable. Needs to be closed or unlinked after use.

Returns:

  • (Tempfile)

    A temporary file with the XML content.



45
46
47
48
49
50
# File 'lib/accession/accessionable.rb', line 45

def to_file
  file = Tempfile.new(['', "_#{filename}"]) # preserve original filename as the filename suffix
  file.write("#{to_xml}\n")
  file.rewind
  file
end

#to_xmlObject

Template method for XML representation. Including classes should override build_xml(xml) to define their XML structure.



34
35
36
37
38
39
# File 'lib/accession/accessionable.rb', line 34

def to_xml
  xml = Builder::XmlMarkup.new
  xml.instruct!
  build_xml(xml)
  xml.target!
end