Class: VORuby::VOTable::V1_1::Stream

Inherits:
Base show all
Defined in:
lib/voruby/votable/1.1/votable.rb

Overview

Represents a stream of bytes, either local or remote.

Constant Summary collapse

ELEMENT_NAME =
'STREAM'

Instance Attribute Summary

Attributes inherited from XML::Object::Base

#node

Instance Method Summary collapse

Methods inherited from Base

#==, element_name, #get_element, #xpath_for

Methods inherited from XML::Object::Base

#==, element_name, from_file, #to_s

Constructor Details

#initialize(defn = nil) ⇒ Stream

Create a new retrieval stream.

stream = Stream.new(:href => 'ftp://server.com/mydata.dat')


1805
1806
1807
1808
1809
1810
# File 'lib/voruby/votable/1.1/votable.rb', line 1805

def initialize(defn=nil)
  super(defn)
  self.type = 'locator' if !self.type
  self.actuate = 'onRequest' if !self.actuate
  self.encoding = 'none' if !self.encoding
end

Instance Method Details

#actuateObject



1835
1836
1837
# File 'lib/voruby/votable/1.1/votable.rb', line 1835

def actuate
  self.node['actuate']
end

#actuate=(a) ⇒ Object

Set when the stream should be retrieved. Possible values are: onLoad, onRequest, other or none. Default is onRequest. In this implementation the value of this parameter doesn’t effect when the stream is retrieved– you must always use #retrieve.



1844
1845
1846
# File 'lib/voruby/votable/1.1/votable.rb', line 1844

def actuate=(a)
  @node['actuate'] = a.to_s
end

#encodingObject



1848
1849
1850
# File 'lib/voruby/votable/1.1/votable.rb', line 1848

def encoding
  self.node['encoding']
end

#encoding=(e) ⇒ Object

Set the encoding of the stream (i.e. base64). Default is none.



1854
1855
1856
# File 'lib/voruby/votable/1.1/votable.rb', line 1854

def encoding=(e)
  @node['encoding'] = e.to_s
end

#expiresObject

Retrieve when the data in the stream expires. Returns a DateTime object.



1860
1861
1862
# File 'lib/voruby/votable/1.1/votable.rb', line 1860

def expires
  self.node['expires'] ? DateTime.parse(self.node['expires']) : nil
end

#expires=(e) ⇒ Object

Set when the data in the stream expires.



1865
1866
1867
# File 'lib/voruby/votable/1.1/votable.rb', line 1865

def expires=(e)
  @node['expires'] = e.to_s
end

#hrefObject

Retrieve the URL of the stream. Returns a URI object.



1824
1825
1826
# File 'lib/voruby/votable/1.1/votable.rb', line 1824

def href
  self.node['href'] ? URI.parse(self.node['href']) : nil
end

#href=(h) ⇒ Object

Set the URL of the stream.

link.href = 'http://www.noao.edu/my.dat' # or...
link.href = URI.parse('http://www.noao.edu/my.dat')


1831
1832
1833
# File 'lib/voruby/votable/1.1/votable.rb', line 1831

def href=(h)
  @node['href'] = h.to_s
end

#retrieveObject

Retrieve the document specified by #href. Returns a File object, of if the document is directly embedded in the stream a StringIO object.



1897
1898
1899
1900
1901
1902
1903
1904
1905
# File 'lib/voruby/votable/1.1/votable.rb', line 1897

def retrieve
  shref = self.href
  
  if shref
    shref.scheme == 'file' ? File.open(shref.path) : open(shref.to_s)
  else
    StringIO.new(self.text)
  end
end

#rightsObject



1869
1870
1871
# File 'lib/voruby/votable/1.1/votable.rb', line 1869

def rights
  self.node['rights']
end

#rights=(r) ⇒ Object

Set any authentication information necessary to access the remote resource (i.e. a password to an encrypted document). The current implementation ignores this value when retrieving the stream.



1877
1878
1879
# File 'lib/voruby/votable/1.1/votable.rb', line 1877

def rights=(r)
  @node['rights'] = r.to_s
end

#textObject

If the stream is text-based, it can be directly embedded within the document, and can be retrieved with this method.



1883
1884
1885
# File 'lib/voruby/votable/1.1/votable.rb', line 1883

def text
  self.node['content']
end

#text=(txt) ⇒ Object

If the stream is text-based it can be directly embedded with this method.

stream.text = 'AAAAAj/yVZiDGSSUwFZ6ypR4yGkADwAcQV0euAAIAAJBmMzNwZWZmkGle4tBR3jVQT9ocwAA'


1890
1891
1892
# File 'lib/voruby/votable/1.1/votable.rb', line 1890

def text=(txt)
  @node['content'] = txt.to_s
end

#typeObject



1812
1813
1814
# File 'lib/voruby/votable/1.1/votable.rb', line 1812

def type
  self.node['type']
end

#type=(t) ⇒ Object

Set the type of stream. May be one of: locator or other. Default is locator.



1818
1819
1820
# File 'lib/voruby/votable/1.1/votable.rb', line 1818

def type=(t)
  @node['type'] = t.to_s
end