Module: VORuby::Resources::STScI

Defined in:
lib/voruby/resources/stsci.rb

Defined Under Namespace

Classes: ArrayOfResource

Class Method Summary collapse

Class Method Details

.clean(doc) ⇒ Object

STScI’s registry has some quirks which we’d like to clean up a bit.



32
33
34
# File 'lib/voruby/resources/stsci.rb', line 32

def self.clean(doc)
  return STScI::remove_empty_elements(STScI::remove_invalid_ivo_ids(doc))
end

.remove_empty_elements(doc) ⇒ Object

Sometimes STScI puts empty elements (no attributes at all) into its resource definitions (particularly in the curation element). I don’t think this is valid–if an element exists at all, it should have some kind of content. Therefore I remove all elements who have no attributes and no children.



49
50
51
52
53
54
55
# File 'lib/voruby/resources/stsci.rb', line 49

def self.remove_empty_elements(doc)
  doc.elements.each('//*'){ |el|
    el.parent.delete_element(el) if !el.has_attributes? and !el.has_elements? and !el.has_text?
  }
  
  return doc
end

.remove_invalid_ivo_ids(doc) ⇒ Object

STScI occasionally puts ‘NOT PROVIDED’ or ” in the ivo-id attribute of (in particular) the publisher element which is not valid. This removes the ivo-id in that situation.



38
39
40
41
42
43
44
# File 'lib/voruby/resources/stsci.rb', line 38

def self.remove_invalid_ivo_ids(doc)
  doc.elements.each('//*[@ivo-id="NOT PROVIDED" or @ivo-id=""]'){ |el|
    el.delete_attribute('ivo-id')
  }

  return doc
end