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