voruby 1.1 → 1.1.1

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.
@@ -1,410 +0,0 @@
1
- # A set of classes designed to read and manipulate
2
- # especific VOTables[http://www.ivoa.net/Documents/latest/VOT.html].
3
- # This class represents a NSA R3 VOTable.
4
-
5
- require 'voruby/votables/votable'
6
-
7
- module VORuby
8
- module VOTables
9
-
10
- module VOTable
11
- class NSAR3VOTable < VOTable
12
-
13
- # Our object's contructor
14
- # [_votable:_]
15
- # The VOTable object
16
- def initialize(votable)
17
- super(votable.id, votable.version, votable.description,
18
- votable.definitions, votable.coosys, votable.params,
19
- votable.info, votable.resources)
20
- end
21
-
22
- # Find the column number(s) associated with a Name.
23
- # Returns a list of column positions.
24
- # [_res_:]
25
- # The resource from which to extract the table in question.
26
- # [_tbl_:]
27
- # The resource from which to extract the table in question.
28
- def find_columns(name, res=0, tbl=0)
29
- columns = []
30
-
31
- col_count = 0
32
- fields = fields(res, tbl)
33
- if fields
34
- fields.each do |field|
35
- if field.name() != nil
36
- columns.push(col_count) if field.name() == name
37
- end
38
- col_count += 1
39
- end
40
- end
41
- return columns
42
- end
43
-
44
- # Find a field in NSA R3 configuration file given a key.
45
- # Returns a hash with the field's attributes
46
- # [_key_:]
47
- # The key indexing on field's attribute.
48
- def find_field_in_conf_file(key)
49
- nsa_field = {'id'=> nil, 'name'=> nil, 'ucd'=> nil}
50
-
51
- if key != nil
52
- NSAR3_ARCHIVE_CONFIG.each do |archive|
53
- archive['votable_fields'].each do |field|
54
- if field['key'] == key
55
- nsa_field['id'] = field['id'] if field['id'] != 'nil'
56
- nsa_field['name'] = field['name'] if field['name'] != 'nil'
57
- nsa_field['ucd'] = field['ucd'] if field['ucd'] != 'nil'
58
- break
59
- end
60
- end
61
- end
62
- end
63
- return nsa_field
64
- end
65
-
66
- def image_access_reference_columns()
67
- access_key = find_field_in_conf_file('Reference')['name']
68
-
69
- if find_columns(access_key).first != nil
70
- find_columns(access_key).first
71
- end
72
- end
73
-
74
- def image_ra_columns
75
- ra_key = find_field_in_conf_file('ra')['name']
76
-
77
- if find_columns(ra_key).first != nil
78
- find_columns(ra_key).first
79
- end
80
- end
81
-
82
- def image_dec_columns
83
- dec_key = find_field_in_conf_file('dec')['name']
84
-
85
- if find_columns(dec_key).first != nil
86
- find_columns(dec_key).first
87
- end
88
- end
89
-
90
- def image_filter_columns
91
- #filter_key = find_field_in_conf_file('')['name']
92
-
93
- #if find_columns(filter_key).first != nil
94
- # find_columns(filter_key).first
95
- #end
96
- end
97
-
98
- def image_date_obs_columns
99
- #date_obs_key = find_field_in_conf_file('')['name']
100
-
101
- #if find_columns(date_obs_key).first != nil
102
- # find_columns(date_obs_key).first
103
- #end
104
- end
105
-
106
- def image_telescope_columns
107
- #telescope_key = find_field_in_conf_file('')['name']
108
-
109
- #if find_columns(telescope_key).first != nil
110
- # find_columns(telescope_key).first
111
- #end
112
- end
113
-
114
- def image_survey_columns
115
- survey_key = find_field_in_conf_file('prop_id')['name']
116
-
117
- if find_columns(survey_key).first != nil
118
- find_columns(survey_key).first
119
- end
120
- end
121
-
122
- def image_instrument_columns
123
- instrument_key = find_field_in_conf_file('instrument')['name']
124
-
125
- if find_columns(instrument_key).first != nil
126
- find_columns(instrument_key).first
127
- end
128
- end
129
-
130
- def image_sky_columns
131
- #sky_key = find_field_in_conf_file('')['name']
132
-
133
- #if find_columns(sky_key).first != nil
134
- # find_columns(sky_key).first
135
- #end
136
- end
137
-
138
- def image_zeropoint_columns
139
- #zeropoint_key = find_field_in_conf_file('')['name']
140
-
141
- #if find_columns(zeropoint_key).first != nil
142
- # find_columns(zeropoint_key).first
143
- #end
144
- end
145
-
146
- def image_seeing_columns
147
- seeing_key = find_field_in_conf_file('seeing')['name']
148
-
149
- if find_columns(seeing_key).first != nil
150
- find_columns(seeing_key).first
151
- end
152
- end
153
-
154
- def image_depth_columns
155
- depth_key = find_field_in_conf_file('depth')['name']
156
-
157
- if find_columns(depth_key).first != nil
158
- find_columns(depth_key).first
159
- end
160
- end
161
-
162
- def image_exptime_columns
163
- #exptime_key = find_field_in_conf_file('')['name']
164
-
165
- #if find_columns(exptime_key).first != nil
166
- # find_columns(exptime_key).first
167
- #end
168
- end
169
-
170
- # Create headers for HTML table
171
- # [_res_:]
172
- # The resource from which to extract the table in question.
173
- # [_tbl_:]
174
- # The table inside the resource from which to extract the rows in question.
175
- # [_infer_add_to_cart_ref_:]
176
- #
177
- # [_add_to_cart_header_value_:]
178
- #
179
- # [_infer_access_ref_:]
180
- # Link the access reference URL associated with a row.
181
- # [_access_ref_header_value_:]
182
- # For the access reference column, place this value in the header.
183
- # [_access_ref_col_:]
184
- # A valid SIA VOTable will only ever have one VOX:Image_AccessReference.
185
- # [_header_class_:]
186
- # The class to assign the header of the HTML table.
187
- def create_headers(res, tbl,
188
- infer_add_to_cart_ref, add_to_cart_header_value,
189
- infer_access_ref, access_ref_header_value, access_ref_col,
190
- header_class, id=nil)
191
-
192
- headers = Array.new
193
- thead = "<thead class=\"#{header_class}\">\n"
194
-
195
- thead << "<tr>\n"
196
- if infer_add_to_cart_ref
197
- thead << "<th>#{add_to_cart_header_value}</th>\n"
198
- headers.push("<a href=\"javascript:void(0);\" onclick=\"siap.addAllRowsToCart('#{id}');\">*</a>")
199
- end
200
- if infer_access_ref
201
- thead << "<th>#{access_ref_header_value}</th>\n"
202
- headers.push('&nbsp;')
203
- end
204
- col_count = 0
205
- fields(res, tbl).each do |field|
206
- field_archive = find_field_in_conf_file(field.name)
207
- field_ucd = field_archive['ucd']
208
- if infer_access_ref and col_count == access_ref_col
209
- headers[1] = field_ucd if field_ucd != 'nil'
210
- else
211
- thead << "<th>#{field_archive['name']}</th>\n"
212
- if field_ucd != 'nil'
213
- headers.push(field_ucd)
214
- else
215
- headers.push('&nbsp;')
216
- end
217
- end
218
- col_count += 1
219
- end
220
- thead << " </tr>\n"
221
-
222
- thead << "<tr>\n"
223
- headers.each do |h|
224
- thead << "<th>#{h}</th>\n"
225
- end
226
- thead << "</tr>\n"
227
-
228
- thead << "</thead>"
229
-
230
- return thead
231
- end
232
-
233
- def create_add_to_cart_link(link_ref, columns)
234
- access_ref_col = image_access_reference_columns()
235
- link_ref << '&resource=' + CGI.escape(columns[access_ref_col].value).to_s if access_ref_col
236
- ra_col = image_ra_columns()
237
- link_ref << '&rac=' + columns[ra_col].value.to_s if ra_col
238
- dec_col = image_dec_columns()
239
- link_ref << '&decc=' + columns[dec_col].value.to_s if dec_col
240
- filter_col = image_filter_columns()
241
- link_ref << '&filter=' + columns[filter_col].value.to_s if filter_col
242
- date_obs_col = image_date_obs_columns()
243
- link_ref << '&date_obs=' + columns[date_obs_col].value.to_s if date_obs_col
244
- teles_col = image_telescope_columns()
245
- link_ref << '&telescop=' + columns[teles_col].value.to_s if teles_col
246
- survey_col = image_survey_columns()
247
- link_ref << '&survey=' + columns[survey_col].value.to_s if survey_col
248
- instrum_col = image_instrument_columns()
249
- link_ref << '&instrument=' + columns[instrum_col].value.to_s if instrum_col
250
- sky_col = image_sky_columns()
251
- link_ref << '&sky=' + columns[sky_col].value.to_s if sky_col
252
- zerop_col = image_zeropoint_columns()
253
- link_ref << '&zeropoint=' + columns[zerop_col].value.to_s if zerop_col
254
- seeing_col = image_seeing_columns()
255
- link_ref << '&seeing=' + columns[seeing_col].value.to_s if seeing_col
256
- depth_col = image_depth_columns()
257
- link_ref << '&depth=' + columns[depth_col].value.to_s if depth_col
258
- exptime_col = image_exptime_columns()
259
- link_ref << '&exptime=' + columns[exptime_col].value.to_s if exptime_col
260
-
261
- return link_ref
262
- end
263
-
264
- # Create body for HTML table
265
- # [_res_:]
266
- # The resource from which to extract the table in question.
267
- # [_tbl_:]
268
- # The table inside the resource from which to extract the rows in question.
269
- # [_infer_add_to_cart_ref_:]
270
- #
271
- # [_add_to_cart_link_value_:]
272
- #
273
- # [_add_to_cart_link_ref_:]
274
- #
275
- # [_infer_access_ref_:]
276
- # Link the access reference URL associated with a row.
277
- # [_access_ref_link_value_:]
278
- # For the access reference column, link this word.
279
- # [_access_ref_col_:]
280
- # A valid SIA VOTable will only ever have one VOX:Image_AccessReference.
281
- # [_body_class_:]
282
- # The class to assign the body of the HTML table.
283
- # [_row_classes_:]
284
- # The class to assign the HTML table body rows.
285
- def create_body(res, tbl,
286
- infer_add_to_cart_ref, add_to_cart_link_value, add_to_cart_link_ref,
287
- infer_access_ref, access_ref_link_value, access_ref_col,
288
- body_class, row_classes)
289
-
290
- tbody = "<tbody class=\"#{body_class}\">\n"
291
- row_count = 0
292
- rows(res, tbl).each do |tr|
293
- tbody << "<tr class=\"#{row_classes[row_count % 2]}\">\n"
294
-
295
- # Specially mark up the first column to link to the image.
296
- columns = tr.tds()
297
-
298
- if infer_add_to_cart_ref
299
- archive = add_to_cart_link_ref.slice(add_to_cart_link_ref.index('&archive='), add_to_cart_link_ref.length)
300
- archive = archive.slice('&archive='.length, archive.length)
301
- archive = archive.slice(0, archive.index('&')) if archive.index('&')
302
- link_id = 'add_' + archive.to_s + '_' + row_count.to_s
303
- url = create_add_to_cart_link(add_to_cart_link_ref, columns)
304
- js = "new Ajax.Request('#{url}', " +
305
- " {method: 'post', " +
306
- " onComplete: function(request){Element.hide('#{link_id}');}});"
307
- tbody << "<td><a id=\"#{link_id}\" href=\"javascript:void(0);\" " +
308
- "onclick=\"#{js};return false;\"" +
309
- ">#{add_to_cart_link_value}</a></td>\n"
310
- end
311
- if infer_access_ref
312
- link_ref = columns[access_ref_col].value
313
- tbody << "<td><a href=\"#{link_ref}\">#{access_ref_link_value}</a></td>\n"
314
- end
315
-
316
- col_count = 0
317
- columns.each do |td|
318
- tbody << "<td>#{td.value}</td>\n" if infer_access_ref and col_count != access_ref_col
319
- col_count += 1
320
- end
321
- tbody << "</tr>\n"
322
- row_count += 1
323
- end
324
- tbody << "</tbody>"
325
-
326
- return tbody
327
- end
328
-
329
- # Convert the specified table in the specified resource into an HTML
330
- # table.
331
- # [_id_:]
332
- # The ID to assign to the HTML table as a whole.
333
- # [_add_to_cart_link_ref_:]
334
- #
335
- # [_res_:]
336
- # The resource from which to extract the table in question.
337
- # [_tbl_:]
338
- # The table inside the resource from which to extract the rows in question.
339
- # [_infer_add_to_cart_ref_:]
340
- #
341
- # [_add_to_cart_header_value_:]
342
- #
343
- # [_add_to_cart_link_value_:]
344
- #
345
- # [_infer_access_ref_:]
346
- # Link the access reference URL associated with a row.
347
- # [_access_ref_header_value_:]
348
- # For the access reference column, place this value in the header.
349
- # [_access_ref_link_value_:]
350
- # For the access reference column, link this word.
351
- # [_show_border_:]
352
- # The boolean value to show HTML table border
353
- # [_table_class_:]
354
- # The class to assign the HTML table as a whole.
355
- # [_header_class_:]
356
- # The class to assign the header of the HTML table.
357
- # [_body_class_:]
358
- # The class to assign the body of the HTML table.
359
- # [_row_classes_:]
360
- # The class to assign the HTML table body rows.
361
- def to_html(id=nil, add_to_cart_link_ref=nil, res=0, tbl=0,
362
- infer_add_to_cart_ref=true,
363
- add_to_cart_header_value='Add to Cart',
364
- add_to_cart_link_value='Add',
365
- infer_access_ref=true,
366
- access_ref_header_value='URL',
367
- access_ref_link_value='Retrieve',
368
- show_border=false,
369
- table_class='votable',
370
- header_class='header',
371
- body_class='body',
372
- row_classes=['row1', 'row2'])
373
- begin
374
- # A valid SIA VOTable will only ever have one VOX:Image_AccessReference.
375
- access_ref_col = image_access_reference_columns()
376
-
377
- if access_ref_col
378
- # Create headers
379
- thead = create_headers(res, tbl,
380
- infer_add_to_cart_ref, add_to_cart_header_value,
381
- infer_access_ref, access_ref_header_value, access_ref_col,
382
- header_class, id)
383
-
384
- # Create body
385
- tbody = create_body(res, tbl,
386
- infer_add_to_cart_ref, add_to_cart_link_value, add_to_cart_link_ref,
387
- infer_access_ref, access_ref_link_value, access_ref_col,
388
- body_class, row_classes)
389
-
390
- return create_table(id, show_border, table_class, thead, tbody)
391
- else
392
- title = 'No Data'
393
- message = 'VOTable not contains data.'
394
- return create_message_table(table_class, header_class,
395
- body_class, row_classes, title, message)
396
- end
397
-
398
- rescue Exception => e
399
- title = 'Error'
400
- message = @resources[0].info[0].text().to_s()
401
- table = create_message_table(table_class, header_class,
402
- body_class, row_classes, title, message)
403
- end
404
- end
405
-
406
- end
407
- end
408
-
409
- end
410
- end