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
-
#ebi_alias ⇒ Object
readonly
Returns the value of attribute ebi_alias.
Instance Method Summary collapse
-
#build_xml(xml) ⇒ Object
Including classes models must implement this method to define their XML content.
- #date ⇒ Object
- #ebi_alias_datestamped ⇒ Object
- #filename ⇒ Object
- #schema_type ⇒ Object
-
#to_file ⇒ Tempfile
Creates a Tempfile containing the XML representation of the accessionable.
-
#to_xml ⇒ Object
Template method for XML representation.
Instance Attribute Details
#ebi_alias ⇒ Object (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
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 |
#date ⇒ Object
11 12 13 |
# File 'lib/accession/accessionable.rb', line 11 def date @date ||= Time.now.utc.iso8601 end |
#ebi_alias_datestamped ⇒ Object
15 16 17 |
# File 'lib/accession/accessionable.rb', line 15 def ebi_alias_datestamped "#{ebi_alias}-#{date}" end |
#filename ⇒ Object
19 20 21 |
# File 'lib/accession/accessionable.rb', line 19 def filename @filename ||= clean_path("#{ebi_alias_datestamped}.#{schema_type}.xml") end |
#schema_type ⇒ Object
7 8 9 |
# File 'lib/accession/accessionable.rb', line 7 def schema_type @schema_type ||= self.class.to_s.demodulize.downcase end |
#to_file ⇒ Tempfile
Creates a Tempfile containing the XML representation of the accessionable. Needs to be closed or unlinked after use.
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_xml ⇒ Object
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 |