Class: VORuby::VOTable::V1_0::Resource

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

Overview

A description and the data values of some logically independent data structure within the VOTable.

Constant Summary collapse

ELEMENT_NAME =
'RESOURCE'

Instance Attribute Summary

Attributes inherited from XML::Object::Base

#node

Class Method Summary collapse

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) ⇒ Resource

Create a new resource.

res = Resource.new(
  :name => 'myFavouriteGalaxies',
  :type => 'meta',
  :params => [Param.new()],
  :links => [Link.new()],
  :tables => [Table.new()]
)


519
520
521
# File 'lib/voruby/votable/1.0/votable.rb', line 519

def initialize(defn=nil)
  super(defn)
end

Class Method Details

.serialization_orderObject



504
505
506
507
508
509
# File 'lib/voruby/votable/1.0/votable.rb', line 504

def self.serialization_order
  [
    :description, :infos, :coordinate_systems, :params, :links, :tables, :resources,
    :id, :name, :type
  ]
end

Instance Method Details

#coordinate_systemsObject

Retrieve the coordinate systems (Coosys). Returns a HomogeneousNodeList.



576
577
578
# File 'lib/voruby/votable/1.0/votable.rb', line 576

def coordinate_systems
  HomogeneousNodeList.new(self.node, xpath_for(Coosys), Coosys)
end

#coordinate_systems=(systems) ⇒ Object

Set the coordinate systems (Coosys).

res.coordinate_systems = [Coosys.new(), ...]


582
583
584
# File 'lib/voruby/votable/1.0/votable.rb', line 582

def coordinate_systems=(systems)
  self.coordinate_systems.replace(systems)
end

#descriptionObject

Retrieve the description (Description).



552
553
554
# File 'lib/voruby/votable/1.0/votable.rb', line 552

def description
  get_element(Description)
end

#description=(d) ⇒ Object

Set the description (Description).

res.description = Description.new(:text => 'A fascinating resource')


558
559
560
# File 'lib/voruby/votable/1.0/votable.rb', line 558

def description=(d)
  set_element(Description, d)
end

#idObject



531
532
533
# File 'lib/voruby/votable/1.0/votable.rb', line 531

def id
  self.node['ID']
end

#id=(i) ⇒ Object



535
536
537
# File 'lib/voruby/votable/1.0/votable.rb', line 535

def id=(i)
  @node['ID'] = i.to_s
end

#infosObject

Retrieve the name-value pairs (Info). Returns a HomogeneousNodeList.



564
565
566
# File 'lib/voruby/votable/1.0/votable.rb', line 564

def infos
   HomogeneousNodeList.new(self.node, xpath_for(Info), Info)
end

#infos=(is) ⇒ Object

Set any name-value pairs.

res.infos = [Info.new(), ...]


570
571
572
# File 'lib/voruby/votable/1.0/votable.rb', line 570

def infos=(is)
  self.infos.replace(is)
end

Retrieve the links (Link). Returns a HomogeneousNodeList.



603
604
605
# File 'lib/voruby/votable/1.0/votable.rb', line 603

def links
   HomogeneousNodeList.new(self.node, xpath_for(Link), Link)
end

#links=(lnks) ⇒ Object

Set the links (Link).

res.links = [Link.new(), ...]


609
610
611
# File 'lib/voruby/votable/1.0/votable.rb', line 609

def links=(lnks)
  self.links.replace(lnks)
end

#nameObject



523
524
525
# File 'lib/voruby/votable/1.0/votable.rb', line 523

def name
  self.node['name']
end

#name=(n) ⇒ Object



527
528
529
# File 'lib/voruby/votable/1.0/votable.rb', line 527

def name=(n)
  @node['name'] = n.to_s
end

#paramsObject

Retrieve the parameters (Param). Returns a HomogeneousNodeList.



588
589
590
# File 'lib/voruby/votable/1.0/votable.rb', line 588

def params
  HomogeneousNodeList.new(self.node, xpath_for(Param), Param)
end

#params=(parameters) ⇒ Object

Set the parameters (Param).

res.params = [Param.new(), ...]


594
595
596
597
598
599
# File 'lib/voruby/votable/1.0/votable.rb', line 594

def params=(parameters)
  self.params.clear
  parameters.each do |p|
    self.params << p
  end
end

#resourcesObject

Retrieve sub-resources (Resource). Returns a HomogeneousNodeList.



627
628
629
# File 'lib/voruby/votable/1.0/votable.rb', line 627

def resources
  HomogeneousNodeList.new(self.node, xpath_for(Resource), Resource)
end

#resources=(res) ⇒ Object

Set sub-resources.

res.resources = [Resource.new(), ...]


633
634
635
# File 'lib/voruby/votable/1.0/votable.rb', line 633

def resources=(res)
  self.resources.replace(res)
end

#tablesObject

Retrieve the tables (Table). Returns a HomogeneousNodeList.



615
616
617
# File 'lib/voruby/votable/1.0/votable.rb', line 615

def tables
  HomogeneousNodeList.new(self.node, xpath_for(Table), Table)
end

#tables=(tbls) ⇒ Object

Set the tables (Table).

res.tables = [Table.new(), ....]


621
622
623
# File 'lib/voruby/votable/1.0/votable.rb', line 621

def tables=(tbls)
  self.tables.replace(tbls)
end

#to_htmlObject

Convert a resource to HTML.



638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
# File 'lib/voruby/votable/1.0/votable.rb', line 638

def to_html
  builder = Builder::XmlMarkup.new(:indent => 2, :margin => 1)
  
  resource_opts = {:class => 'resource'}
  resource_opts[:id] = self.id if self.id
  
  builder.div(resource_opts){ |resource|
    resource.h3(self.name) if self.name
    resource.div(self.description.text, :class => 'description') if self.description
  
    self.tables.each do |tbl|
      resource << tbl.to_html
    end
    
    self.resources.each do |res|
      resource << res.to_html
    end
  }
end

#typeObject

Retrieve the type. A type of ‘meta’ means that the resource is descriptive only (does not contain any actual data in any of its sub-elements).



542
543
544
# File 'lib/voruby/votable/1.0/votable.rb', line 542

def type
  self.node['type']
end

#type=(t) ⇒ Object

Set the type.



547
548
549
# File 'lib/voruby/votable/1.0/votable.rb', line 547

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