Class: VORuby::VOTable::V1_0::Stream

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

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

Represents a stream of bytes, either local or remote.



1515
1516
1517
1518
1519
1520
# File 'lib/voruby/votable/1.0/votable.rb', line 1515

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



1545
1546
1547
# File 'lib/voruby/votable/1.0/votable.rb', line 1545

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.



1554
1555
1556
# File 'lib/voruby/votable/1.0/votable.rb', line 1554

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

#encodingObject



1558
1559
1560
# File 'lib/voruby/votable/1.0/votable.rb', line 1558

def encoding
  self.node['encoding']
end

#encoding=(e) ⇒ Object

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



1564
1565
1566
# File 'lib/voruby/votable/1.0/votable.rb', line 1564

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

#expiresObject



1568
1569
1570
# File 'lib/voruby/votable/1.0/votable.rb', line 1568

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

#expires=(e) ⇒ Object

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



1574
1575
1576
# File 'lib/voruby/votable/1.0/votable.rb', line 1574

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

#hrefObject

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



1534
1535
1536
# File 'lib/voruby/votable/1.0/votable.rb', line 1534

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')


1541
1542
1543
# File 'lib/voruby/votable/1.0/votable.rb', line 1541

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.



1606
1607
1608
1609
1610
1611
1612
1613
1614
# File 'lib/voruby/votable/1.0/votable.rb', line 1606

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



1578
1579
1580
# File 'lib/voruby/votable/1.0/votable.rb', line 1578

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.



1586
1587
1588
# File 'lib/voruby/votable/1.0/votable.rb', line 1586

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.



1592
1593
1594
# File 'lib/voruby/votable/1.0/votable.rb', line 1592

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'


1599
1600
1601
# File 'lib/voruby/votable/1.0/votable.rb', line 1599

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

#typeObject



1522
1523
1524
# File 'lib/voruby/votable/1.0/votable.rb', line 1522

def type
  self.node['type']
end

#type=(t) ⇒ Object

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



1528
1529
1530
# File 'lib/voruby/votable/1.0/votable.rb', line 1528

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