Class: VORuby::VOTables::VOTable::NSAR3VOTable
- Inherits:
-
VORuby::VOTables::VOTable
- Object
- VORuby::VOTables::VOTable
- VORuby::VOTables::VOTable::NSAR3VOTable
- Defined in:
- lib/voruby/votables/nsar3.rb
Instance Method Summary collapse
- #create_add_to_cart_link(link_ref, columns) ⇒ Object
-
#create_body(res, tbl, infer_add_to_cart_ref, add_to_cart_link_value, add_to_cart_link_ref, infer_access_ref, access_ref_link_value, access_ref_col, body_class, row_classes) ⇒ Object
Create body for HTML table [res:] The resource from which to extract the table in question.
-
#create_headers(res, tbl, infer_add_to_cart_ref, add_to_cart_header_value, infer_access_ref, access_ref_header_value, access_ref_col, header_class, id = nil) ⇒ Object
Create headers for HTML table [res:] The resource from which to extract the table in question.
-
#find_columns(name, res = 0, tbl = 0) ⇒ Object
Find the column number(s) associated with a Name.
-
#find_field_in_conf_file(key) ⇒ Object
Find a field in NSA R3 configuration file given a key.
- #image_access_reference_columns ⇒ Object
- #image_date_obs_columns ⇒ Object
- #image_dec_columns ⇒ Object
- #image_depth_columns ⇒ Object
- #image_exptime_columns ⇒ Object
- #image_filter_columns ⇒ Object
- #image_instrument_columns ⇒ Object
- #image_ra_columns ⇒ Object
- #image_seeing_columns ⇒ Object
- #image_sky_columns ⇒ Object
- #image_survey_columns ⇒ Object
- #image_telescope_columns ⇒ Object
- #image_zeropoint_columns ⇒ Object
-
#initialize(votable) ⇒ NSAR3VOTable
constructor
Our object’s contructor [votable:] The VOTable object.
-
#to_html(id = nil, add_to_cart_link_ref = nil, res = 0, tbl = 0, infer_add_to_cart_ref = true, add_to_cart_header_value = 'Add to Cart', add_to_cart_link_value = 'Add', infer_access_ref = true, access_ref_header_value = 'URL', access_ref_link_value = 'Retrieve', show_border = false, table_class = 'votable', header_class = 'header', body_class = 'body', row_classes = ['row1', 'row2']) ⇒ Object
Convert the specified table in the specified resource into an HTML table.
Constructor Details
#initialize(votable) ⇒ NSAR3VOTable
Our object’s contructor
- votable:
-
The VOTable object
16 17 18 19 20 |
# File 'lib/voruby/votables/nsar3.rb', line 16 def initialize(votable) super(votable.id, votable.version, votable.description, votable.definitions, votable.coosys, votable.params, votable.info, votable.resources) end |
Instance Method Details
#create_add_to_cart_link(link_ref, columns) ⇒ Object
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/voruby/votables/nsar3.rb', line 233 def create_add_to_cart_link(link_ref, columns) access_ref_col = image_access_reference_columns() link_ref << '&resource=' + CGI.escape(columns[access_ref_col].value).to_s if access_ref_col ra_col = image_ra_columns() link_ref << '&rac=' + columns[ra_col].value.to_s if ra_col dec_col = image_dec_columns() link_ref << '&decc=' + columns[dec_col].value.to_s if dec_col filter_col = image_filter_columns() link_ref << '&filter=' + columns[filter_col].value.to_s if filter_col date_obs_col = image_date_obs_columns() link_ref << '&date_obs=' + columns[date_obs_col].value.to_s if date_obs_col teles_col = image_telescope_columns() link_ref << '&telescop=' + columns[teles_col].value.to_s if teles_col survey_col = image_survey_columns() link_ref << '&survey=' + columns[survey_col].value.to_s if survey_col instrum_col = image_instrument_columns() link_ref << '&instrument=' + columns[instrum_col].value.to_s if instrum_col sky_col = image_sky_columns() link_ref << '&sky=' + columns[sky_col].value.to_s if sky_col zerop_col = image_zeropoint_columns() link_ref << '&zeropoint=' + columns[zerop_col].value.to_s if zerop_col seeing_col = image_seeing_columns() link_ref << '&seeing=' + columns[seeing_col].value.to_s if seeing_col depth_col = image_depth_columns() link_ref << '&depth=' + columns[depth_col].value.to_s if depth_col exptime_col = image_exptime_columns() link_ref << '&exptime=' + columns[exptime_col].value.to_s if exptime_col return link_ref end |
#create_body(res, tbl, infer_add_to_cart_ref, add_to_cart_link_value, add_to_cart_link_ref, infer_access_ref, access_ref_link_value, access_ref_col, body_class, row_classes) ⇒ Object
Create body for HTML table
- res:
-
The resource from which to extract the table in question.
- tbl:
-
The table inside the resource from which to extract the rows in question.
- infer_add_to_cart_ref:
- add_to_cart_link_value:
- add_to_cart_link_ref:
- infer_access_ref:
- add_to_cart_link_value:
-
Link the access reference URL associated with a row.
- access_ref_link_value:
-
For the access reference column, link this word.
- access_ref_col:
-
A valid SIA VOTable will only ever have one VOX:Image_AccessReference.
- body_class:
-
The class to assign the body of the HTML table.
- row_classes:
-
The class to assign the HTML table body rows.
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/voruby/votables/nsar3.rb', line 285 def create_body(res, tbl, infer_add_to_cart_ref, add_to_cart_link_value, add_to_cart_link_ref, infer_access_ref, access_ref_link_value, access_ref_col, body_class, row_classes) tbody = "<tbody class=\"#{body_class}\">\n" row_count = 0 rows(res, tbl).each do |tr| tbody << "<tr class=\"#{row_classes[row_count % 2]}\">\n" # Specially mark up the first column to link to the image. columns = tr.tds() if infer_add_to_cart_ref archive = add_to_cart_link_ref.slice(add_to_cart_link_ref.index('&archive='), add_to_cart_link_ref.length) archive = archive.slice('&archive='.length, archive.length) archive = archive.slice(0, archive.index('&')) if archive.index('&') link_id = 'add_' + archive.to_s + '_' + row_count.to_s url = create_add_to_cart_link(add_to_cart_link_ref, columns) js = "new Ajax.Request('#{url}', " + " {method: 'post', " + " onComplete: function(request){Element.hide('#{link_id}');}});" tbody << "<td><a id=\"#{link_id}\" href=\"javascript:void(0);\" " + "onclick=\"#{js};return false;\"" + ">#{add_to_cart_link_value}</a></td>\n" end if infer_access_ref link_ref = columns[access_ref_col].value tbody << "<td><a href=\"#{link_ref}\">#{access_ref_link_value}</a></td>\n" end col_count = 0 columns.each do |td| tbody << "<td>#{td.value}</td>\n" if infer_access_ref and col_count != access_ref_col col_count += 1 end tbody << "</tr>\n" row_count += 1 end tbody << "</tbody>" return tbody end |
#create_headers(res, tbl, infer_add_to_cart_ref, add_to_cart_header_value, infer_access_ref, access_ref_header_value, access_ref_col, header_class, id = nil) ⇒ Object
Create headers for HTML table
- res:
-
The resource from which to extract the table in question.
- tbl:
-
The table inside the resource from which to extract the rows in question.
- infer_add_to_cart_ref:
- add_to_cart_header_value:
- infer_access_ref:
- add_to_cart_header_value:
-
Link the access reference URL associated with a row.
- access_ref_header_value:
-
For the access reference column, place this value in the header.
- access_ref_col:
-
A valid SIA VOTable will only ever have one VOX:Image_AccessReference.
- header_class:
-
The class to assign the header of the HTML table.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/voruby/votables/nsar3.rb', line 187 def create_headers(res, tbl, infer_add_to_cart_ref, add_to_cart_header_value, infer_access_ref, access_ref_header_value, access_ref_col, header_class, id=nil) headers = Array.new thead = "<thead class=\"#{header_class}\">\n" thead << "<tr>\n" if infer_add_to_cart_ref thead << "<th>#{add_to_cart_header_value}</th>\n" headers.push("<a href=\"javascript:void(0);\" onclick=\"siap.addAllRowsToCart('#{id}');\">*</a>") end if infer_access_ref thead << "<th>#{access_ref_header_value}</th>\n" headers.push(' ') end col_count = 0 fields(res, tbl).each do |field| field_archive = find_field_in_conf_file(field.name) field_ucd = field_archive['ucd'] if infer_access_ref and col_count == access_ref_col headers[1] = field_ucd if field_ucd != 'nil' else thead << "<th>#{field_archive['name']}</th>\n" if field_ucd != 'nil' headers.push(field_ucd) else headers.push(' ') end end col_count += 1 end thead << " </tr>\n" thead << "<tr>\n" headers.each do |h| thead << "<th>#{h}</th>\n" end thead << "</tr>\n" thead << "</thead>" return thead end |
#find_columns(name, res = 0, tbl = 0) ⇒ Object
Find the column number(s) associated with a Name. Returns a list of column positions.
- res:
-
The resource from which to extract the table in question.
- tbl:
-
The resource from which to extract the table in question.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/voruby/votables/nsar3.rb', line 28 def find_columns(name, res=0, tbl=0) columns = [] col_count = 0 fields = fields(res, tbl) if fields fields.each do |field| if field.name() != nil columns.push(col_count) if field.name() == name end col_count += 1 end end return columns end |
#find_field_in_conf_file(key) ⇒ Object
Find a field in NSA R3 configuration file given a key. Returns a hash with the field’s attributes
- key:
-
The key indexing on field’s attribute.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/voruby/votables/nsar3.rb', line 48 def find_field_in_conf_file(key) nsa_field = {'id'=> nil, 'name'=> nil, 'ucd'=> nil} if key != nil NSAR3_ARCHIVE_CONFIG.each do |archive| archive['votable_fields'].each do |field| if field['key'] == key nsa_field['id'] = field['id'] if field['id'] != 'nil' nsa_field['name'] = field['name'] if field['name'] != 'nil' nsa_field['ucd'] = field['ucd'] if field['ucd'] != 'nil' break end end end end return nsa_field end |
#image_access_reference_columns ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/voruby/votables/nsar3.rb', line 66 def image_access_reference_columns() access_key = find_field_in_conf_file('Reference')['name'] if find_columns(access_key).first != nil find_columns(access_key).first end end |
#image_date_obs_columns ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/voruby/votables/nsar3.rb', line 98 def image_date_obs_columns #date_obs_key = find_field_in_conf_file('')['name'] #if find_columns(date_obs_key).first != nil # find_columns(date_obs_key).first #end end |
#image_dec_columns ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/voruby/votables/nsar3.rb', line 82 def image_dec_columns dec_key = find_field_in_conf_file('dec')['name'] if find_columns(dec_key).first != nil find_columns(dec_key).first end end |
#image_depth_columns ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/voruby/votables/nsar3.rb', line 154 def image_depth_columns depth_key = find_field_in_conf_file('depth')['name'] if find_columns(depth_key).first != nil find_columns(depth_key).first end end |
#image_exptime_columns ⇒ Object
162 163 164 165 166 167 168 |
# File 'lib/voruby/votables/nsar3.rb', line 162 def image_exptime_columns #exptime_key = find_field_in_conf_file('')['name'] #if find_columns(exptime_key).first != nil # find_columns(exptime_key).first #end end |
#image_filter_columns ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/voruby/votables/nsar3.rb', line 90 def image_filter_columns #filter_key = find_field_in_conf_file('')['name'] #if find_columns(filter_key).first != nil # find_columns(filter_key).first #end end |
#image_instrument_columns ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/voruby/votables/nsar3.rb', line 122 def image_instrument_columns instrument_key = find_field_in_conf_file('instrument')['name'] if find_columns(instrument_key).first != nil find_columns(instrument_key).first end end |
#image_ra_columns ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/voruby/votables/nsar3.rb', line 74 def image_ra_columns ra_key = find_field_in_conf_file('ra')['name'] if find_columns(ra_key).first != nil find_columns(ra_key).first end end |
#image_seeing_columns ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/voruby/votables/nsar3.rb', line 146 def image_seeing_columns seeing_key = find_field_in_conf_file('seeing')['name'] if find_columns(seeing_key).first != nil find_columns(seeing_key).first end end |
#image_sky_columns ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/voruby/votables/nsar3.rb', line 130 def image_sky_columns #sky_key = find_field_in_conf_file('')['name'] #if find_columns(sky_key).first != nil # find_columns(sky_key).first #end end |
#image_survey_columns ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/voruby/votables/nsar3.rb', line 114 def image_survey_columns survey_key = find_field_in_conf_file('prop_id')['name'] if find_columns(survey_key).first != nil find_columns(survey_key).first end end |
#image_telescope_columns ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/voruby/votables/nsar3.rb', line 106 def image_telescope_columns #telescope_key = find_field_in_conf_file('')['name'] #if find_columns(telescope_key).first != nil # find_columns(telescope_key).first #end end |
#image_zeropoint_columns ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/voruby/votables/nsar3.rb', line 138 def image_zeropoint_columns #zeropoint_key = find_field_in_conf_file('')['name'] #if find_columns(zeropoint_key).first != nil # find_columns(zeropoint_key).first #end end |
#to_html(id = nil, add_to_cart_link_ref = nil, res = 0, tbl = 0, infer_add_to_cart_ref = true, add_to_cart_header_value = 'Add to Cart', add_to_cart_link_value = 'Add', infer_access_ref = true, access_ref_header_value = 'URL', access_ref_link_value = 'Retrieve', show_border = false, table_class = 'votable', header_class = 'header', body_class = 'body', row_classes = ['row1', 'row2']) ⇒ Object
Convert the specified table in the specified resource into an HTML table.
- id:
-
The ID to assign to the HTML table as a whole.
- add_to_cart_link_ref:
- res:
-
The resource from which to extract the table in question.
- tbl:
-
The table inside the resource from which to extract the rows in question.
- infer_add_to_cart_ref:
- add_to_cart_header_value:
- add_to_cart_link_value:
- infer_access_ref:
- add_to_cart_header_value:
-
Link the access reference URL associated with a row.
- access_ref_header_value:
-
For the access reference column, place this value in the header.
- access_ref_link_value:
-
For the access reference column, link this word.
- show_border:
-
The boolean value to show HTML table border
- table_class:
-
The class to assign the HTML table as a whole.
- header_class:
-
The class to assign the header of the HTML table.
- body_class:
-
The class to assign the body of the HTML table.
- row_classes:
-
The class to assign the HTML table body rows.
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/voruby/votables/nsar3.rb', line 361 def to_html(id=nil, add_to_cart_link_ref=nil, res=0, tbl=0, infer_add_to_cart_ref=true, add_to_cart_header_value='Add to Cart', add_to_cart_link_value='Add', infer_access_ref=true, access_ref_header_value='URL', access_ref_link_value='Retrieve', show_border=false, table_class='votable', header_class='header', body_class='body', row_classes=['row1', 'row2']) begin # A valid SIA VOTable will only ever have one VOX:Image_AccessReference. access_ref_col = image_access_reference_columns() if access_ref_col # Create headers thead = create_headers(res, tbl, infer_add_to_cart_ref, add_to_cart_header_value, infer_access_ref, access_ref_header_value, access_ref_col, header_class, id) # Create body tbody = create_body(res, tbl, infer_add_to_cart_ref, add_to_cart_link_value, add_to_cart_link_ref, infer_access_ref, access_ref_link_value, access_ref_col, body_class, row_classes) return create_table(id, show_border, table_class, thead, tbody) else title = 'No Data' = 'VOTable not contains data.' return (table_class, header_class, body_class, row_classes, title, ) end rescue Exception => e title = 'Error' = @resources[0].info[0].text().to_s() table = (table_class, header_class, body_class, row_classes, title, ) end end |