voruby 1.1.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile.rb +107 -224
- data/lib/misc.rb +1 -0
- data/lib/misc/misc.rb +60 -0
- data/lib/misc/propertyfile.rb +31 -0
- data/lib/symphony.rb +1 -0
- data/lib/symphony/symphony.rb +247 -0
- data/lib/voruby.rb +186 -0
- data/lib/voruby/active_votable/active_votable.rb +468 -347
- data/lib/voruby/adql/1.0/adql.rb +2418 -0
- data/lib/voruby/adql/support.rb +2 -0
- data/lib/voruby/misc.rb +351 -0
- data/lib/voruby/misc/connection_monitor.rb +97 -0
- data/lib/voruby/misc/libxml_ext.rb +121 -0
- data/lib/voruby/misc/rexml_ext.rb +223 -0
- data/lib/voruby/resolver/resolver.rb +12 -0
- data/lib/voruby/resolver/sesame.rb +299 -0
- data/lib/voruby/sky_query/sky_query.rb +192 -0
- data/lib/voruby/stc/1.10/coords.rb +2272 -0
- data/lib/voruby/stc/1.10/region.rb +892 -0
- data/lib/voruby/stc/1.10/stc.rb +3271 -0
- data/lib/voruby/stc/1.30/stc.rb +8666 -0
- data/lib/voruby/stc/support.rb +2 -0
- data/lib/voruby/ucd/ucd.rb +173 -0
- data/lib/voruby/voevent/1.1/voevent.rb +1124 -0
- data/lib/voruby/voevent/support.rb +5 -0
- data/lib/voruby/votable/1.0/votable.rb +1807 -0
- data/lib/voruby/votable/1.1/votable.rb +2100 -0
- data/lib/voruby/votable/votable.rb +305 -0
- data/lib/voruby/wesix/wesix.rb +491 -0
- data/lib/voruby/xlink/1.2/xlink.rb +21 -0
- data/test/voruby/active_votable/complex.vot +60 -0
- data/test/voruby/active_votable/error.vot +6 -0
- data/test/voruby/active_votable/large.vot +130040 -0
- data/test/voruby/active_votable/simple1.vot +38 -0
- data/test/voruby/active_votable/simple2.vot +38 -0
- data/test/voruby/active_votable/test.rb +193 -0
- data/test/voruby/adql/1.0/adql-alias.sql +1 -0
- data/test/voruby/adql/1.0/adql-alias.xml +26 -0
- data/test/voruby/adql/1.0/adql-avg.sql +1 -0
- data/test/voruby/adql/1.0/adql-avg.xml +31 -0
- data/test/voruby/adql/1.0/adql-circle.sql +1 -0
- data/test/voruby/adql/1.0/adql-circle.xml +46 -0
- data/test/voruby/adql/1.0/adql-expr.sql +1 -0
- data/test/voruby/adql/1.0/adql-expr.xml +34 -0
- data/test/voruby/adql/1.0/adql-function.sql +1 -0
- data/test/voruby/adql/1.0/adql-function.xml +41 -0
- data/test/voruby/adql/1.0/adql-group.sql +1 -0
- data/test/voruby/adql/1.0/adql-group.xml +51 -0
- data/test/voruby/adql/1.0/adql-having.sql +1 -0
- data/test/voruby/adql/1.0/adql-having.xml +25 -0
- data/test/voruby/adql/1.0/adql-like.sql +1 -0
- data/test/voruby/adql/1.0/adql-like.xml +17 -0
- data/test/voruby/adql/1.0/adql-order.sql +1 -0
- data/test/voruby/adql/1.0/adql-order.xml +37 -0
- data/test/voruby/adql/1.0/adql-simple.sql +1 -0
- data/test/voruby/adql/1.0/adql-simple.xml +12 -0
- data/test/voruby/adql/1.0/adql-top.sql +1 -0
- data/test/voruby/adql/1.0/adql-top.xml +33 -0
- data/test/voruby/adql/1.0/test.rb +2220 -0
- data/test/voruby/misc/test.rb +32 -0
- data/test/voruby/resolver/sesame/test.rb +56 -0
- data/test/voruby/sky_query/test.rb +107 -0
- data/test/voruby/stc/1.10/coords_test.rb +3704 -0
- data/test/voruby/stc/1.10/region_test.rb +993 -0
- data/test/voruby/stc/1.10/stc-catalog-entry-location.xml +112 -0
- data/test/voruby/stc/1.10/stc-obs-data-location.xml +126 -0
- data/test/voruby/stc/1.10/stc-region-circle.xml +5 -0
- data/test/voruby/stc/1.10/stc-region-convex.xml +11 -0
- data/test/voruby/stc/1.10/stc-region-convexhull.xml +5 -0
- data/test/voruby/stc/1.10/stc-region-ellipse.xml +7 -0
- data/test/voruby/stc/1.10/stc-region-intersection.xml +25 -0
- data/test/voruby/stc/1.10/stc-region-negation.xml +7 -0
- data/test/voruby/stc/1.10/stc-region-polygon.xml +13 -0
- data/test/voruby/stc/1.10/stc-region-sector.xml +6 -0
- data/test/voruby/stc/1.10/stc-region-union.xml +25 -0
- data/test/voruby/stc/1.10/stc-resource-profile.xml +60 -0
- data/test/voruby/stc/1.10/stc-search-location.xml +54 -0
- data/test/voruby/stc/1.10/stc_test.rb +4626 -0
- data/test/voruby/stc/1.30/stc-catalog-entry-location.xml +210 -0
- data/test/voruby/stc/1.30/stc-obs-data-location-arecibo.xml +353 -0
- data/test/voruby/stc/1.30/stc-obs-data-location-fits.xml +250 -0
- data/test/voruby/stc/1.30/stc-obs-data-location-xlink.xml +63 -0
- data/test/voruby/stc/1.30/stc-obs-data-location.xml +216 -0
- data/test/voruby/stc/1.30/stc-resource-profile-unusual-ref-pos.xml +39 -0
- data/test/voruby/stc/1.30/stc-resource-profile.xml +129 -0
- data/test/voruby/stc/1.30/stc-search-location-arecibo.xml +86 -0
- data/test/voruby/stc/1.30/stc-search-location.xml +101 -0
- data/test/voruby/stc/1.30/test.rb +6274 -0
- data/test/voruby/ucd/test.rb +48 -0
- data/test/voruby/voevent/1.1/test.rb +812 -0
- data/test/{voevent/voevent_v1_1.xml → voruby/voevent/1.1/voevent.xml} +2 -2
- data/test/voruby/voregistry/0.3/test.rb +137 -0
- data/test/voruby/votable/1.0/test.rb +714 -0
- data/test/voruby/votable/1.0/votable.basic.xml +660 -0
- data/test/voruby/votable/1.0/votable.html +86 -0
- data/test/voruby/votable/1.0/votable.ns.xml +56 -0
- data/test/voruby/votable/1.1/test.rb +785 -0
- data/test/voruby/votable/1.1/votable.basic.xml +38 -0
- data/test/voruby/votable/1.1/votable.html +86 -0
- data/test/voruby/votable/1.1/votable.ns.xml +56 -0
- data/test/voruby/votable/test.rb +15 -0
- data/test/voruby/wesix/test.rb +268 -0
- data/test/voruby/wesix/testr.fits +28 -0
- metadata +234 -247
- data/REQUIREMENTS +0 -6
- data/lib/voruby/active_votable/loader.rb +0 -5
- data/lib/voruby/adql/adql.rb +0 -2787
- data/lib/voruby/adql/ext.rb +0 -14
- data/lib/voruby/adql/loader.rb +0 -6
- data/lib/voruby/adql/operations.rb +0 -54
- data/lib/voruby/adql/parser.rb +0 -160
- data/lib/voruby/adql/transforms.rb +0 -573
- data/lib/voruby/ext.rb +0 -17
- data/lib/voruby/loader.rb +0 -4
- data/lib/voruby/misc/propertyfile.rb +0 -36
- data/lib/voruby/plastic/applications.rb +0 -174
- data/lib/voruby/plastic/constants.rb +0 -30
- data/lib/voruby/plastic/loader.rb +0 -10
- data/lib/voruby/plastic/plastic.rb +0 -1
- data/lib/voruby/resources/conesearch/conesearch.rb +0 -9
- data/lib/voruby/resources/conesearch/conesearch_v0_2.rb +0 -55
- data/lib/voruby/resources/conesearch/conesearch_v0_3.rb +0 -50
- data/lib/voruby/resources/conesearch/conesearch_v1_0.rb +0 -72
- data/lib/voruby/resources/conesearch/loader.rb +0 -4
- data/lib/voruby/resources/loader.rb +0 -50
- data/lib/voruby/resources/nodes.rb +0 -190
- data/lib/voruby/resources/openskynode/loader.rb +0 -4
- data/lib/voruby/resources/openskynode/openskynode.rb +0 -9
- data/lib/voruby/resources/openskynode/openskynode_v0_1.rb +0 -54
- data/lib/voruby/resources/sia/loader.rb +0 -5
- data/lib/voruby/resources/sia/sia.rb +0 -9
- data/lib/voruby/resources/sia/sia_v0_6.rb +0 -90
- data/lib/voruby/resources/sia/sia_v0_7.rb +0 -89
- data/lib/voruby/resources/sia/sia_v1_0.rb +0 -122
- data/lib/voruby/resources/stsci.rb +0 -59
- data/lib/voruby/resources/vodataservice/coverage_v0_2.rb +0 -195
- data/lib/voruby/resources/vodataservice/coverage_v0_3.rb +0 -158
- data/lib/voruby/resources/vodataservice/loader.rb +0 -5
- data/lib/voruby/resources/vodataservice/vodataservice.rb +0 -9
- data/lib/voruby/resources/vodataservice/vodataservice_v0_4.rb +0 -189
- data/lib/voruby/resources/vodataservice/vodataservice_v0_5.rb +0 -163
- data/lib/voruby/resources/vodataservice/vodataservice_v1_0.rb +0 -221
- data/lib/voruby/resources/voregistry/loader.rb +0 -4
- data/lib/voruby/resources/voregistry/voregistry.rb +0 -9
- data/lib/voruby/resources/voregistry/voregistry_v0_2.rb +0 -40
- data/lib/voruby/resources/voregistry/voregistry_v0_3.rb +0 -30
- data/lib/voruby/resources/voregistry/voregistry_v1_0.rb +0 -86
- data/lib/voruby/resources/voresource/loader.rb +0 -17
- data/lib/voruby/resources/voresource/voresource.rb +0 -9
- data/lib/voruby/resources/voresource/voresource_v0_10.rb +0 -327
- data/lib/voruby/resources/voresource/voresource_v0_9.rb +0 -405
- data/lib/voruby/resources/voresource/voresource_v1_0.rb +0 -230
- data/lib/voruby/services/ext.rb +0 -11
- data/lib/voruby/services/gestalt/footprint.rb +0 -95
- data/lib/voruby/services/gestalt/wcs_fixer.rb +0 -105
- data/lib/voruby/services/gestalt/wesix.rb +0 -155
- data/lib/voruby/services/loader.rb +0 -7
- data/lib/voruby/services/registry/registry.rb +0 -53
- data/lib/voruby/services/resolver/resolver.rb +0 -35
- data/lib/voruby/services/schema/schema.rb +0 -644
- data/lib/voruby/sesame/loader.rb +0 -6
- data/lib/voruby/sesame/sesame_v1_0.rb +0 -64
- data/lib/voruby/simple/loader.rb +0 -6
- data/lib/voruby/simple/parameters.rb +0 -196
- data/lib/voruby/simple/sap.rb +0 -446
- data/lib/voruby/spacetime/loader.rb +0 -3
- data/lib/voruby/spacetime/spacetime.rb +0 -607
- data/lib/voruby/stc/coords_v1_20.rb +0 -900
- data/lib/voruby/stc/loader.rb +0 -55
- data/lib/voruby/stc/region_v1_20.rb +0 -274
- data/lib/voruby/stc/stc_v1_20.rb +0 -1196
- data/lib/voruby/util.rb +0 -27
- data/lib/voruby/voevent/loader.rb +0 -7
- data/lib/voruby/voevent/voevent_v1_0.rb +0 -213
- data/lib/voruby/voevent/voevent_v1_1.rb +0 -196
- data/lib/voruby/votables/chandra.rb +0 -373
- data/lib/voruby/votables/data.rb +0 -179
- data/lib/voruby/votables/galex.rb +0 -377
- data/lib/voruby/votables/int.rb +0 -354
- data/lib/voruby/votables/libxml_parser.rb +0 -411
- data/lib/voruby/votables/libxml_votable.rb +0 -67
- data/lib/voruby/votables/loader.rb +0 -10
- data/lib/voruby/votables/meta.rb +0 -763
- data/lib/voruby/votables/misc.rb +0 -51
- data/lib/voruby/votables/nsa.rb +0 -410
- data/lib/voruby/votables/rexml_parser.rb +0 -408
- data/lib/voruby/votables/rexml_votable.rb +0 -67
- data/lib/voruby/votables/sdss.rb +0 -356
- data/lib/voruby/votables/transforms.rb +0 -388
- data/lib/voruby/votables/tree.rb +0 -45
- data/lib/voruby/votables/types.rb +0 -391
- data/lib/voruby/votables/votable.rb +0 -687
- data/test/active_votable/database.yml +0 -6
- data/test/active_votable/test.vot +0 -168492
- data/test/active_votable/unittest.rb +0 -41
- data/test/adql/test1.adql +0 -49
- data/test/adql/test2.adql +0 -51
- data/test/adql/test3.adql +0 -81
- data/test/adql/test4.adql +0 -53
- data/test/adql/test5.adql +0 -55
- data/test/adql/test6.adql +0 -18
- data/test/adql/test7.adql +0 -48
- data/test/adql/unittest.rb +0 -1672
- data/test/plastic/test.rb +0 -44
- data/test/plastic/test.vot +0 -5385
- data/test/plastic/unittest.rb +0 -66
- data/test/resources/conesearch/conesearch_v0_3.xml +0 -31
- data/test/resources/conesearch/conesearch_v1_0.xml +0 -86
- data/test/resources/conesearch/unittest_v0_3.rb +0 -22
- data/test/resources/conesearch/unittest_v1_0.rb +0 -24
- data/test/resources/openskynode/open_sky_node_v0_1.xml +0 -32
- data/test/resources/openskynode/unittest_v0_1.rb +0 -31
- data/test/resources/sia/simple_image_access_v0_7.xml +0 -36
- data/test/resources/sia/simple_image_access_v1_0.xml +0 -122
- data/test/resources/sia/unittest_v0_7.rb +0 -24
- data/test/resources/sia/unittest_v1_0.rb +0 -29
- data/test/resources/stsci.xml +0 -336
- data/test/resources/unittest_stsci.rb +0 -25
- data/test/resources/vodataservice/catalog_service_resource_v1_0.xml +0 -128
- data/test/resources/vodataservice/data_collection_resource_v0_5.xml +0 -54
- data/test/resources/vodataservice/data_collection_resource_v1_0.xml +0 -117
- data/test/resources/vodataservice/data_service_resource_v1_0.xml +0 -115
- data/test/resources/vodataservice/sky_service_resource_v0_10.xml +0 -45
- data/test/resources/vodataservice/table_service_resource_v1_0.xml +0 -122
- data/test/resources/vodataservice/tabular_sky_service_resource_v0_10.xml +0 -60
- data/test/resources/vodataservice/unittest_v0_5.rb +0 -126
- data/test/resources/vodataservice/unittest_v1_0.rb +0 -151
- data/test/resources/voregistry/authority_resource_v0_3.xml +0 -20
- data/test/resources/voregistry/authority_resource_v1_0.xml +0 -82
- data/test/resources/voregistry/registry_service_v0_3.xml +0 -20
- data/test/resources/voregistry/registry_service_v1_0.xml +0 -107
- data/test/resources/voregistry/unittest_v0_3.rb +0 -31
- data/test/resources/voregistry/unittest_v1_0.rb +0 -34
- data/test/resources/voresource/organisation_resource_v1_0.xml +0 -90
- data/test/resources/voresource/resource_organisation_v0_10.xml +0 -22
- data/test/resources/voresource/resource_service_v0_10.xml +0 -19
- data/test/resources/voresource/resource_v0_10.xml +0 -19
- data/test/resources/voresource/resource_v1_0.xml +0 -79
- data/test/resources/voresource/service_resource_v1_0.xml +0 -91
- data/test/resources/voresource/unittest_v0_10.rb +0 -61
- data/test/resources/voresource/unittest_v0_9.rb +0 -4
- data/test/resources/voresource/unittest_v1_0.rb +0 -190
- data/test/services/gestalt/unittest.rb +0 -74
- data/test/services/registry/unittest.rb +0 -34
- data/test/services/resolver/unittest.rb +0 -38
- data/test/simple/unittest.rb +0 -46
- data/test/spacetime/unittest.rb +0 -39
- data/test/stc/catalog_entry_location_v1_20.xml +0 -112
- data/test/stc/obs_data_location_v1_20.xml +0 -108
- data/test/stc/search_location_v1_20.xml +0 -54
- data/test/stc/stc_resource_profile_v1_20.xml +0 -60
- data/test/stc/unittest_v1_20.rb +0 -620
- data/test/voevent/unittest_v1_0.rb +0 -79
- data/test/voevent/unittest_v1_1.rb +0 -70
- data/test/voevent/voevent_v1_0.xml +0 -96
- data/test/votables/test.vot +0 -366
- data/test/votables/unittest.rb +0 -54
@@ -0,0 +1,31 @@
|
|
1
|
+
module PropertyFile
|
2
|
+
# A *very* simple property file reader.
|
3
|
+
# It can only understand files with entries
|
4
|
+
# of the property=value format--nothing fancy.
|
5
|
+
class SimpleReader
|
6
|
+
def initialize(file_name)
|
7
|
+
@file_name = file_name
|
8
|
+
load()
|
9
|
+
end
|
10
|
+
|
11
|
+
def load
|
12
|
+
@properties = {}
|
13
|
+
File.open(@file_name) do |file|
|
14
|
+
file.each do |line|
|
15
|
+
line.lstrip!
|
16
|
+
if line !~ /^\#/
|
17
|
+
key, value = line.split(/\s*=\s*/, 2)
|
18
|
+
@properties[key] = value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def [](name)
|
25
|
+
@properties[name]
|
26
|
+
end
|
27
|
+
|
28
|
+
private :load
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/lib/symphony.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'symphony/symphony'
|
@@ -0,0 +1,247 @@
|
|
1
|
+
class HomogeneousArray < Array
|
2
|
+
attr_reader :klass
|
3
|
+
|
4
|
+
def initialize(of_class, *spec)
|
5
|
+
of_class = [of_class] if !of_class.is_a?(Array)
|
6
|
+
@klass = of_class
|
7
|
+
|
8
|
+
spec.flatten.each { |obj| raise_type_error(obj) if !self.acceptable_type?(obj) }
|
9
|
+
|
10
|
+
super(*spec)
|
11
|
+
end
|
12
|
+
|
13
|
+
def raise_type_error(obj)
|
14
|
+
raise TypeError, "wrong argument type of #{obj.class} #{obj.inspect} (expected #{self.klass})"
|
15
|
+
end
|
16
|
+
|
17
|
+
def []=(*assign_spec)
|
18
|
+
raise_type_error(assign_spec.last) if !self.acceptable_type?(assign_spec.last)
|
19
|
+
super(*assign_spec)
|
20
|
+
end
|
21
|
+
|
22
|
+
def <<(obj)
|
23
|
+
raise_type_error(obj) if !self.acceptable_type?(obj)
|
24
|
+
super(obj)
|
25
|
+
end
|
26
|
+
|
27
|
+
def replace(array_of_obj)
|
28
|
+
array_of_obj.each { |obj| raise_type_error(obj) if !self.acceptable_type?(obj) }
|
29
|
+
super(array_of_obj)
|
30
|
+
end
|
31
|
+
|
32
|
+
def ==(ary)
|
33
|
+
return false if !ary.respond_to?(:size)
|
34
|
+
return false if self.size != ary.size
|
35
|
+
|
36
|
+
self.each_with_index do |el, i|
|
37
|
+
return false if !(el == ary[i])
|
38
|
+
end
|
39
|
+
|
40
|
+
return true
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
def acceptable_type?(obj)
|
45
|
+
self.klass.find_all{ |k| obj.is_a?(k) }.size > 0
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class MinimumSizedHomogeneousArray < HomogeneousArray
|
50
|
+
attr_reader :min_size
|
51
|
+
|
52
|
+
def initialize(min_size, of_class, *spec)
|
53
|
+
raise_size_error(spec.last.size, min_size) if spec.last.size < min_size
|
54
|
+
|
55
|
+
super(of_class, *spec)
|
56
|
+
@min_size = min_size
|
57
|
+
end
|
58
|
+
|
59
|
+
def delete(obj)
|
60
|
+
raise_size_error(self.size - 1, self.min_size) if self.size - 1 < self.min_size
|
61
|
+
super(obj)
|
62
|
+
end
|
63
|
+
|
64
|
+
def delete_at(index)
|
65
|
+
raise_size_error(self.size - 1, self.min_size) if self.size - 1 < self.min_size
|
66
|
+
super(index)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def raise_size_error(size, min_size=nil)
|
71
|
+
raise ArgumentError, "array of size #{size} can not shrink below a capacity of #{min_size || self.min_size}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class AtLeastTwoArray < MinimumSizedHomogeneousArray
|
76
|
+
def initialize(of_class, *spec)
|
77
|
+
super(2, of_class, *spec)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class FixedSizedHomogeneousArray < HomogeneousArray
|
82
|
+
attr_reader :capacity
|
83
|
+
|
84
|
+
def initialize(capacity, of_class, *spec)
|
85
|
+
raise_capacity_error(spec.last.size, capacity) if spec.last.size != capacity
|
86
|
+
|
87
|
+
super(of_class, *spec)
|
88
|
+
@capacity = capacity
|
89
|
+
end
|
90
|
+
|
91
|
+
def []=(*assign_spec)
|
92
|
+
super(*assign_spec)
|
93
|
+
raise_capacity_error(self.size) if self.size != self.capacity
|
94
|
+
end
|
95
|
+
|
96
|
+
def <<(obj)
|
97
|
+
raise_capacity_error(self.size + 1) if self.size + 1 != self.capacity
|
98
|
+
super(obj)
|
99
|
+
end
|
100
|
+
|
101
|
+
def replace(array_of_obj)
|
102
|
+
aise_capacity_error(self.size + array_of_obj.size) if self.size + array_of_obj.size != self.capacity
|
103
|
+
super(array_of_obj)
|
104
|
+
end
|
105
|
+
|
106
|
+
def delete(obj); end
|
107
|
+
def delete_at(index); end
|
108
|
+
|
109
|
+
private
|
110
|
+
def raise_capacity_error(size, capacity=nil)
|
111
|
+
raise ArgumentError, "array incorrect size of #{size} (expected #{capacity || self.capacity})"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
class Array
|
116
|
+
def to_homogeneous(of_type)
|
117
|
+
harray = HomogeneousArray.new(of_type)
|
118
|
+
self.each{ |item| harray << item }
|
119
|
+
harray
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
module Symphony
|
124
|
+
module ClassMethods
|
125
|
+
DEFAULT_OPTIONS = {
|
126
|
+
:of => Object,
|
127
|
+
:optional => false,
|
128
|
+
:nillable => false
|
129
|
+
}
|
130
|
+
|
131
|
+
attr_reader :symphony_definitions
|
132
|
+
|
133
|
+
def initialize_symphony_definitions
|
134
|
+
@symphony_definitions ||= []
|
135
|
+
end
|
136
|
+
|
137
|
+
def has(multiplicity, name, options={})
|
138
|
+
initialize_symphony_definitions()
|
139
|
+
|
140
|
+
raise ArgumentError, "multiplicity must be an integer or a symbol (i.e. :many)" if !multiplicity.is_a?(Integer) and !multiplicity.is_a?(Symbol)
|
141
|
+
|
142
|
+
options = DEFAULT_OPTIONS.merge(options)
|
143
|
+
defn = {:multiplicity => multiplicity, :method_name => name.to_sym, :options => options}
|
144
|
+
@symphony_definitions << defn
|
145
|
+
|
146
|
+
create_methods(defn)
|
147
|
+
end
|
148
|
+
|
149
|
+
def has_one(name, options)
|
150
|
+
has 1, name, options
|
151
|
+
end
|
152
|
+
|
153
|
+
def has_many(name, options)
|
154
|
+
has :many, name, options
|
155
|
+
end
|
156
|
+
|
157
|
+
def create_methods(defn)
|
158
|
+
# reader
|
159
|
+
class_eval "
|
160
|
+
def #{defn[:method_name]}
|
161
|
+
puts '#{defn[:method_name]}:' + self.class.symphony_definitions.find{ |d| d[:method_name] == :#{defn[:method_name]} }.inspect
|
162
|
+
@#{defn[:method_name]} || self.class.symphony_definitions.find{ |d| d[:method_name] == :#{defn[:method_name]} }[:options][:default]
|
163
|
+
end
|
164
|
+
"
|
165
|
+
|
166
|
+
# writer
|
167
|
+
check_method = (defn[:multiplicity] == :many or defn[:multiplicity] > 1) ? 'check_made_of_only' : 'check_type'
|
168
|
+
class_eval "
|
169
|
+
def #{defn[:method_name]}=(obj)
|
170
|
+
raise TypeError, \"#{defn[:method_name]} is not nillable\" if !#{defn[:options][:nillable]} and obj == nil
|
171
|
+
#{check_method}(#{defn[:options][:of]}, obj) if obj != nil or !#{defn[:options][:nillable]}
|
172
|
+
|
173
|
+
@#{defn[:method_name]} = obj
|
174
|
+
end
|
175
|
+
"
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
class << self
|
181
|
+
def included(klass)
|
182
|
+
super
|
183
|
+
klass.__send__(:extend, ClassMethods)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
class Symphony::Base
|
189
|
+
include Symphony
|
190
|
+
|
191
|
+
def initialize(args={})
|
192
|
+
self.class.initialize_symphony_definitions()
|
193
|
+
validate(args)
|
194
|
+
assign_initial_values(args)
|
195
|
+
end
|
196
|
+
|
197
|
+
def ==(obj)
|
198
|
+
return false if !obj.is_a?(self.class)
|
199
|
+
|
200
|
+
self.class.symphony_definitions.each do |defn|
|
201
|
+
return false if self.send(defn[:method_name]) != obj.send(defn[:method_name])
|
202
|
+
end
|
203
|
+
|
204
|
+
return true
|
205
|
+
end
|
206
|
+
|
207
|
+
private
|
208
|
+
|
209
|
+
def check_type(klass, o)
|
210
|
+
raise TypeError, "wrong argument type of #{o.class} #{o.inspect} (expected #{klass})" if !o.is_a?(klass)
|
211
|
+
end
|
212
|
+
|
213
|
+
def check_made_of_only(klass, list)
|
214
|
+
list.each { |o| check_type(klass, o) }
|
215
|
+
end
|
216
|
+
|
217
|
+
def validate(args)
|
218
|
+
self.class.symphony_definitions.each do |defn|
|
219
|
+
raise ArgumentError, "#{defn[:method_name]} is missing but is required" if !defn[:options][:optional] and !args.has_key?(defn[:method_name])
|
220
|
+
raise TypeError, "#{defn[:method_name]} is not nillable" if args.has_key?(defn[:method_name]) and args[defn[:method_name]] == nil and !defn[:options][:nillable]
|
221
|
+
|
222
|
+
values = args[defn[:method_name]]
|
223
|
+
values = values.is_a?(Array) ? values : [values]
|
224
|
+
|
225
|
+
# if defn[:multiplicity].is_a?(Integer)
|
226
|
+
# raise ArgumentError, "wrong number of arguments for #{defn[:method_name]} (#{values.size} for #{defn[:multiplicity]})" if values.size != defn[:multiplicity]
|
227
|
+
# elsif defn[:multiplicity].is_a?(Symbol)
|
228
|
+
# raise ArgumentError, "don't know what a multiplicity of #{defn[:multiplicity]} means" if defn[:multiplicity] != :many
|
229
|
+
# end
|
230
|
+
|
231
|
+
raise ArgumentError, "don't know what a multiplicity of #{defn[:multiplicity]} means" if !defn[:multiplicity].is_a?(Integer) and defn[:multiplicity] != :many
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def assign_initial_values(args)
|
236
|
+
self.class.symphony_definitions.each do |defn|
|
237
|
+
values = if !args[defn[:method_name]].is_a?(HomogeneousArray) and args[defn[:method_name]].is_a?(Array)
|
238
|
+
args[defn[:method_name]].to_homogeneous(defn[:options][:of])
|
239
|
+
else
|
240
|
+
check_type(defn[:options][:of], args[defn[:method_name]]) if !defn[:options][:optional] and (!defn[:options][:nillable] and args[defn[:method_name]] != nil)
|
241
|
+
args[defn[:method_name]]
|
242
|
+
end
|
243
|
+
|
244
|
+
send("#{defn[:method_name]}=", values)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
data/lib/voruby.rb
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
module VORuby
|
2
|
+
begin
|
3
|
+
require 'rfits'
|
4
|
+
rescue LoadError
|
5
|
+
@@rfits_available = false
|
6
|
+
else
|
7
|
+
@@rfits_available = true
|
8
|
+
end
|
9
|
+
|
10
|
+
# Reports whether the RFits[http://rubyforge.org/projects/rfits]
|
11
|
+
# FITS reading/writing package is installed or not.
|
12
|
+
def self.rfits?
|
13
|
+
@@rfits_available
|
14
|
+
end
|
15
|
+
|
16
|
+
# An array-like class that uses an XML::Node to back itself.
|
17
|
+
# Designed to work in concert with a VOTable::Base object
|
18
|
+
# or at least something with a _node_ method and a _new_
|
19
|
+
# method that takes a XML::Node object.
|
20
|
+
# Mixes in Enumerable for added functionality.
|
21
|
+
class HomogeneousNodeList
|
22
|
+
include Enumerable
|
23
|
+
|
24
|
+
# The XPath expression to the child node(s) of the list.
|
25
|
+
attr_reader :xpath
|
26
|
+
|
27
|
+
# The class of the sub-objects allowed in the list.
|
28
|
+
attr_reader :klass
|
29
|
+
|
30
|
+
# Create a new node list.
|
31
|
+
# _node_ is the XML::Node that all operation will be mirrored on.
|
32
|
+
# _xpath_ is the the XPath expression used to retrieve the
|
33
|
+
# children of _node_ that make up the list.
|
34
|
+
# _klass_ is the class of those children.
|
35
|
+
#
|
36
|
+
# vot = VOTable.new({
|
37
|
+
# :version => '1.1',
|
38
|
+
# :id => 'my_test_votable',
|
39
|
+
# :description => Description.new,
|
40
|
+
# :definitions => Definitions.new,
|
41
|
+
# :coordinate_systems => [Coosys.new],
|
42
|
+
# :params => [Param.new],
|
43
|
+
# :infos => [Info.new],
|
44
|
+
# :resources => [Resource.new]
|
45
|
+
# })
|
46
|
+
# node_list = HomogeneousNodeList.new(vot, 'COOSYS', VOTable::V_1::Coosys)
|
47
|
+
def initialize(node, xpath, klass)
|
48
|
+
@node = node.is_a?(XML::Node) ? node : node.node
|
49
|
+
@xpath = xpath
|
50
|
+
@klass = klass
|
51
|
+
end
|
52
|
+
|
53
|
+
# Iterate through each member of the list.
|
54
|
+
# node_list.each do |obj|
|
55
|
+
# puts obj
|
56
|
+
# end
|
57
|
+
def each
|
58
|
+
@node.find(*self.xpath).each do |e|
|
59
|
+
yield klass.new(e)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Replace the current member of the list with
|
64
|
+
# those specified.
|
65
|
+
# node_list.replace(Coosys.new, Coosys.new, Coosys.new)
|
66
|
+
def replace(*args)
|
67
|
+
self.clear
|
68
|
+
args.flatten.each do |a|
|
69
|
+
self << a
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Append a new member to the end of the list.
|
74
|
+
# node_list << Coosys.new
|
75
|
+
def <<(obj)
|
76
|
+
raise "Expected item of type #{@klass} but was #{obj.class}" if !obj.is_a?(@klass)
|
77
|
+
|
78
|
+
obj.node.name = self.xpath.first.split(':').last if self.xpath.is_a?(Array)
|
79
|
+
|
80
|
+
last_in_list = @node.find_first("*[local-name()='#{obj.node.name}'][last()]")
|
81
|
+
last_in_list ? last_in_list.next = obj.node : @node.child_add(obj.node.copy(true))
|
82
|
+
end
|
83
|
+
|
84
|
+
# Prepend a new member to the beginning of the list.
|
85
|
+
# node_list.prepend(Coosys.new)
|
86
|
+
def prepend(obj)
|
87
|
+
raise "Expected item of type #{@klass} but was #{obj.class}" if !obj.is_a?(@klass)
|
88
|
+
|
89
|
+
obj.node.name = self.xpath.first.split(':').last if self.xpath.is_a?(Array)
|
90
|
+
|
91
|
+
first_in_list = @node.find_first("*[local-name()='#{obj.node.name}'][1]")
|
92
|
+
first_in_list ? first_in_list.prev = obj.node : @node.child_add(obj.node)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Retrieve the ith member of the list. i may be less than one.
|
96
|
+
# coosys2 = node_list[1]
|
97
|
+
def [](i)
|
98
|
+
i = self.length + i if i < 0 # support negative indices
|
99
|
+
|
100
|
+
expr = self.xpath.is_a?(Array) ?
|
101
|
+
["#{self.xpath.first}[#{i+1}]", self.xpath.last] :
|
102
|
+
["#{self.xpath}[#{i+1}]"]
|
103
|
+
|
104
|
+
klass.new(@node.find_first(*expr))
|
105
|
+
end
|
106
|
+
|
107
|
+
# Set the ith member of the list. Setting a member to a location
|
108
|
+
# longer than the current list, appends that member to the end
|
109
|
+
# of the list. In other words, there are no nil members allowed.
|
110
|
+
# node_list[1] = Coosys.new
|
111
|
+
def []=(i, obj)
|
112
|
+
raise "Expected item of type #{@klass} but was #{obj.class}" if !obj.is_a?(@klass)
|
113
|
+
|
114
|
+
i = self.length + i if i < 0 # support negative indices
|
115
|
+
|
116
|
+
expr = self.xpath.is_a?(Array) ?
|
117
|
+
["#{self.xpath.first}[#{i+1}]", self.xpath.last] :
|
118
|
+
["#{self.xpath}[#{i+1}]"]
|
119
|
+
|
120
|
+
obj.node.name = self.xpath.first.split(':').last if self.xpath.is_a?(Array)
|
121
|
+
|
122
|
+
this_node = @node.find_first(*expr)
|
123
|
+
this_node ? this_node.replace_with(obj.node) : self << obj
|
124
|
+
end
|
125
|
+
|
126
|
+
# Delete the ith member in the list.
|
127
|
+
# node_list.delete_at(1) # delete the second coordinate system
|
128
|
+
def delete_at(i)
|
129
|
+
expr = self.xpath.is_a?(Array) ?
|
130
|
+
["#{self.xpath.first}[#{i+1}]", self.xpath.last] :
|
131
|
+
["#{self.xpath}[#{i+1}]"]
|
132
|
+
@node.find_first(*expr).remove!
|
133
|
+
end
|
134
|
+
|
135
|
+
# Clear the list of all its members.
|
136
|
+
# node_list.clear
|
137
|
+
def clear
|
138
|
+
@node.find(*self.xpath).each do |el|
|
139
|
+
el.remove!
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# Pick the first member of the list.
|
144
|
+
# coosys1 = node_list.first
|
145
|
+
def first
|
146
|
+
expr = self.xpath.is_a?(Array) ?
|
147
|
+
["#{self.xpath.first}[1]", self.xpath.last] :
|
148
|
+
["#{self.xpath}[1]"]
|
149
|
+
klass.new(@node.find_first(*expr))
|
150
|
+
end
|
151
|
+
|
152
|
+
# Pick the last member of the list
|
153
|
+
# coosys_last = node_list.last
|
154
|
+
def last
|
155
|
+
expr = self.xpath.is_a?(Array) ?
|
156
|
+
["#{self.xpath.first}[last()]", self.xpath.last] :
|
157
|
+
["#{self.xpath}[last()]"]
|
158
|
+
klass.new(@node.find_first(*expr))
|
159
|
+
end
|
160
|
+
|
161
|
+
# Find the number of members in the list.
|
162
|
+
# node_list.length # => 4
|
163
|
+
def length
|
164
|
+
@node.find(*self.xpath).length
|
165
|
+
end
|
166
|
+
|
167
|
+
# Alias for #length.
|
168
|
+
def size
|
169
|
+
length
|
170
|
+
end
|
171
|
+
|
172
|
+
# Two lists are equivalent if their lengths are equal
|
173
|
+
# and the members of the lists are equal to each other
|
174
|
+
# (and in the same order).
|
175
|
+
def ==(obj)
|
176
|
+
return false if self.length != obj.length
|
177
|
+
|
178
|
+
self.each_with_index do |item, i|
|
179
|
+
return false if obj[i] != item
|
180
|
+
end
|
181
|
+
|
182
|
+
true
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|