Class: Report_html
- Inherits:
-
Object
- Object
- Report_html
- Defined in:
- lib/report_html/report_html.rb
Instance Method Summary collapse
- #add_header_row_names(data, options) ⇒ Object
-
#add_sample_attributes(data_structure, options) ⇒ Object
CANVASXPRESS METHODS ————————————————————————————-.
- #assign_rgb(link_data) ⇒ Object
- #barplot(user_options = {}, &block) ⇒ Object
- #boxplot(user_options = {}, &block) ⇒ Object
- #build(template) ⇒ Object
- #build_body ⇒ Object
- #canvasXpress_main(user_options, block = nil) {|options, config, samples, vars, values, object_id| ... } ⇒ Object
- #circular(user_options = {}, &block) ⇒ Object
- #corplot(user_options = {}, &block) ⇒ Object
-
#embed_img(img_file, img_attribs = nil) ⇒ Object
EMBED FILES.
- #embed_pdf(pdf_file, pdf_attribs = nil) ⇒ Object
- #extract_data(options) ⇒ Object
- #extract_fields(id, fields) ⇒ Object
- #get_cell_align(align_vector, position) ⇒ Object
- #get_col_n_row_span(table) ⇒ Object
-
#get_data(options) ⇒ Object
DATA MANIPULATION METHODS ————————————————————————————-.
-
#get_report ⇒ Object
return all html string.
- #get_span(colspan, rowspan, row, col) ⇒ Object
- #heatmap(user_options = {}, &block) ⇒ Object
-
#initialize(hash_vars, title = "report", data_from_files = false) ⇒ Report_html
constructor
A new instance of Report_html.
- #line(user_options = {}, &block) ⇒ Object
- #load_css(css_files) ⇒ Object
- #load_js_libraries(js_libraries) ⇒ Object
- #make_head ⇒ Object
- #pie(user_options = {}, &block) ⇒ Object
- #prepare_table_attribs(attribs) ⇒ Object
- #scatterbubble2D(user_options = {}, &block) ⇒ Object
- #sccater2D(user_options = {}, &block) ⇒ Object (also: #scatter2D)
- #set_tree(options, config) ⇒ Object
- #stacked(user_options = {}, &block) ⇒ Object
-
#table(user_options = {}, &block) ⇒ Object
TABLE METHODS ————————————————————————————-.
- #tree_from_file(file) ⇒ Object
- #write(file) ⇒ Object
Constructor Details
#initialize(hash_vars, title = "report", data_from_files = false) ⇒ Report_html
Returns a new instance of Report_html.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/report_html/report_html.rb', line 9 def initialize(hash_vars, title = "report", data_from_files = false) @all_report = "" @title = title @hash_vars = hash_vars @data_from_files = data_from_files @plots_data = [] @count_objects = 0 @dt_tables = [] #Tables to be styled with the DataTables js lib" @bs_tables = [] #Tables to be styled with the bootstrap js lib" end |
Instance Method Details
#add_header_row_names(data, options) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/report_html/report_html.rb', line 163 def add_header_row_names(data, ) if [:add_header_row_names] # This check if html object needs a default header/row_names or not if ![:header] range = 0..(data.first.length - 1) data.unshift(range.to_a) end if ![:row_names] data.each_with_index do |row, i| row.unshift(i) end end end end |
#add_sample_attributes(data_structure, options) ⇒ Object
CANVASXPRESS METHODS
329 330 331 332 333 334 335 336 337 |
# File 'lib/report_html/report_html.rb', line 329 def add_sample_attributes(data_structure, ) parsed_sample_attributes = {} [:sample_attributes].each do |key, col| data = get_data({id: [:id], fields: [col], text: true}) data.shift if [:header] parsed_sample_attributes[key] = data.flatten end data_structure['x'] = parsed_sample_attributes end |
#assign_rgb(link_data) ⇒ Object
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
# File 'lib/report_html/report_html.rb', line 624 def assign_rgb(link_data) colors = { 'red' => [255, 0, 0], 'green' => [0, 255, 0], 'black' => [0, 0, 0], 'yellow' => [255, 255, 0], 'blue' => [0, 0, 255], 'gray' => [128, 128, 128], 'orange' => [255, 165, 0], 'cyan' => [0, 255, 255], 'magenta' => [255, 0, 255] } link_data.each do |link| code = colors[link[0]] if !code.nil? link[0] = "rgb(#{code.join(',')})" else raise "Color link #{link} is not allowed. The allowed color names are: #{colors.keys.join(' ')}" end end end |
#barplot(user_options = {}, &block) ⇒ Object
461 462 463 464 465 466 467 468 469 |
# File 'lib/report_html/report_html.rb', line 461 def ( = {}, &block) = { row_names: true }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id| config['graphType'] = 'Bar' end return html_string end |
#boxplot(user_options = {}, &block) ⇒ Object
481 482 483 484 485 486 487 488 489 490 491 492 493 494 |
# File 'lib/report_html/report_html.rb', line 481 def boxplot( = {}, &block) = { row_names: true, header: true }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id| config['graphType'] = 'Boxplot' [:mod_data_structure] = 'boxplot' if [:extracode].nil? [:extracode] = "C#{object_id}.groupSamples([\"Factor\"]);" end end return html_string end |
#build(template) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/report_html/report_html.rb', line 20 def build(template) renderered_template = ERB.new(template).result(binding) @all_report = "<HTML>\n" make_head build_body do renderered_template end @all_report << "\n</HTML>" end |
#build_body ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/report_html/report_html.rb', line 30 def build_body if !@plots_data.empty? @all_report << "<body onload=\"initPage();\">\n#{yield}\n</body>\n" else @all_report << "<body>\n#{yield}\n</body>\n" end end |
#canvasXpress_main(user_options, block = nil) {|options, config, samples, vars, values, object_id| ... } ⇒ Object
355 356 357 358 359 360 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 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/report_html/report_html.rb', line 355 def canvasXpress_main(, block = nil) # Handle arguments #------------------------------------------ = { id: nil, fields: [], data_format: 'one_axis', responsive: true, height: '600px', width: '600px', header: false, row_names: false, add_header_row_names: true, transpose: true, x_label: 'x_axis', title: 'Title', sample_attributes: {}, config: {}, after_render: [], treeBy: 's' } .merge!() config = { 'toolbarType' => 'under', 'xAxisTitle' => [:x_label], 'title' => [:title] } if ![:tree].nil? set_tree(, config) end config.merge!([:config]) # Data manipulation #------------------------------------------ no_data_string = ERB.new("<div width=\"#{[:width]}\" height=\"#{[:height]}\" > <p>NO DATA<p></div>").result(binding) data_array = get_data() return no_data_string if data_array.empty? block.call(data_array) if !block.nil? object_id = "obj_#{@count_objects}_" raise("ID #{[:id]} has not data") if data_array.nil? row_length = data_array.first.length samples = data_array.shift[1..row_length] return no_data_string if data_array.empty? vars = [] data_array.each do |row| vars << row.shift end values = data_array yield(, config, samples, vars, values, object_id) # Build JSON objects and Javascript code #----------------------------------------------- @count_objects += 1 data_structure = { 'y' => { 'vars' => vars, 'smps' => samples, 'data' => values } } events = false info = false afterRender = [:after_render] if [:mod_data_structure] == 'boxplot' data_structure['y']['smps'] = nil data_structure.merge!({ 'x' => {'Factor' => samples}}) elsif [:mod_data_structure] == 'circular' data_structure.merge!({ 'z' => {'Ring' => [:ring_assignation]}}) end add_sample_attributes(data_structure, ) if ![:sample_attributes].empty? extracode = "#{[:extracode]}\n" extracode << "C#{object_id}.groupSamples(#{[:group_samples]})\n" if ![:group_samples].nil? plot_data = " var data = #{data_structure.to_json}; var conf = #{config.to_json}; var events = #{events.to_json}; var info = #{info.to_json}; var afterRender = #{afterRender.to_json}; var C#{object_id} = new CanvasXpress(\"#{object_id}\", data, conf, events, info, afterRender);\n#{extracode}" @plots_data << plot_data responsive = '' responsive = "responsive='true'" if [:responsive] html = "<canvas id=\"#{object_id}\" width=\"#{[:width]}\" height=\"#{[:height]}\" aspectRatio='1:1' #{responsive}></canvas>" return ERB.new(html).result(binding) end |
#circular(user_options = {}, &block) ⇒ Object
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 |
# File 'lib/report_html/report_html.rb', line 588 def circular( = {}, &block) = { ring_assignation: [], ringsType: [], ringsWeight: [] }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id| [:mod_data_structure] = 'circular' config['graphType'] = 'Circular' config['segregateVariablesBy'] = ['Ring'] if [:ringsType].empty? config['ringGraphType'] = Array.new(vars.length, 'heatmap') else config['ringGraphType'] = [:ringsType] end if [:ringsWeight].empty? size = 100/vars.length config['ringGraphWeight'] = Array.new(vars.length, size) else config['ringGraphWeight'] = [:ringsWeight] end if [:ring_assignation].empty? [:ring_assignation] = Array.new(vars.length) {|index| (index + 1).to_s} else [:ring_assignation] = [:ring_assignation].map{|item| item.to_s} end if ![:links].nil? if !@hash_vars[[:links]].nil? && !@hash_vars[[:links]].empty? link_data = get_data({id: [:links], fields: [], add_header_row_names: false, text: true, transpose: false}) config['connections'] = assign_rgb(link_data) end end end return html_string end |
#corplot(user_options = {}, &block) ⇒ Object
512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/report_html/report_html.rb', line 512 def corplot( = {}, &block) = { transpose: false, correlationAxis: 'samples' }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id| config['graphType'] = 'Correlation' config['correlationAxis'] = [:correlationAxis] end return html_string end |
#embed_img(img_file, img_attribs = nil) ⇒ Object
EMBED FILES
649 650 651 652 653 654 655 |
# File 'lib/report_html/report_html.rb', line 649 def (img_file, img_attribs = nil) img_content = File.open(img_file).read img_base64 = Base64.encode64(img_content) format = File.basename(img_file).split('.').last img_string = "<img #{img_attribs} src=\"data:image/#{format};base64,#{img_base64}\">" return img_string end |
#embed_pdf(pdf_file, pdf_attribs = nil) ⇒ Object
657 658 659 660 661 662 |
# File 'lib/report_html/report_html.rb', line 657 def (pdf_file, pdf_attribs = nil) pdf_content = File.open(pdf_file).read pdf_base64 = Base64.encode64(pdf_content) pdf_string = "<embed #{pdf_attribs} src=\"data:application/pdf;base64,#{pdf_base64}\" type=\"application/pdf\"></embed>" return pdf_string end |
#extract_data(options) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/report_html/report_html.rb', line 177 def extract_data() data = [] ids = [:id] fields = [:fields] ids = ids.split(',') if ids.class == String && ids.include?(',') # String syntax if ids.class == Array fields = fields.split(';').map{|data_fields| data_fields.split(',').map{|fields| fields.to_i} } if fields.class == String # String syntax ids.each_with_index do |id, n| data_file = extract_fields(id, fields[n]) if data.empty? data.concat(data_file) else data.each_with_index do |row, n| data[n] = row + data_file[n] end end end else fields = fields.first if fields.class == Array data = extract_fields(ids, [:fields]) end return data end |
#extract_fields(id, fields) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/report_html/report_html.rb', line 201 def extract_fields(id, fields) data = [] @hash_vars[id].each do |row| if fields.empty? data << row.dup # Dup generates a array copy that avoids to modify original objects on data manipulation creating graphs else data << fields.map{|field| row[field]} #Map without bang do the same than dup end end return data end |
#get_cell_align(align_vector, position) ⇒ Object
307 308 309 310 311 312 313 314 |
# File 'lib/report_html/report_html.rb', line 307 def get_cell_align(align_vector, position) cell_align = '' if !align_vector.empty? align = align_vector[position] cell_align = "align=\"#{align}\"" end return cell_align end |
#get_col_n_row_span(table) ⇒ Object
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/report_html/report_html.rb', line 282 def get_col_n_row_span(table) colspan = [] rowspan = [] last_row = 0 table.each_with_index do |row, r| rowspan << Array.new(row.length, 1) colspan << Array.new(row.length, 1) last_col = 0 row.each_with_index do |col, c| if col == 'colspan' colspan[r][last_col] += 1 else last_col = c end if col == 'rowspan' rowspan[last_row][c] += 1 else last_row = r end end end return rowspan, colspan end |
#get_data(options) ⇒ Object
DATA MANIPULATION METHODS
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/report_html/report_html.rb', line 139 def get_data() data = [] data = extract_data() if !data.empty? if @data_from_files # If data on container is loaded using html_report as lib, we don't care about data format # if data comes from files and is loaded as strings. We need to format correctly the data. rows = data.length cols = data.first.length if ![:text] rows.times do |r| cols.times do |c| next if r == 0 && [:header] next if c == 0 && [:row_names] data[r][c] = data[r][c].to_f end end end end add_header_row_names(data, ) data = data.transpose if [:transpose] end return data end |
#get_report ⇒ Object
return all html string
122 123 124 125 |
# File 'lib/report_html/report_html.rb', line 122 def get_report #return all html string renderer = ERB.new(@all_report) return renderer.result(binding) #binding does accesible all the current ruby enviroment to erb end |
#get_span(colspan, rowspan, row, col) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/report_html/report_html.rb', line 269 def get_span(colspan, rowspan, row, col) span = [] colspan_value = colspan[row][col] rowspan_value = rowspan[row][col] if colspan_value > 1 span << "colspan=\"#{colspan_value}\"" end if rowspan_value > 1 span << "rowspan=\"#{rowspan_value}\"" end return span.join(' ') end |
#heatmap(user_options = {}, &block) ⇒ Object
471 472 473 474 475 476 477 478 479 |
# File 'lib/report_html/report_html.rb', line 471 def heatmap( = {}, &block) = { row_names: true }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id| config['graphType'] = 'Heatmap' end return html_string end |
#line(user_options = {}, &block) ⇒ Object
441 442 443 444 445 446 447 448 449 |
# File 'lib/report_html/report_html.rb', line 441 def line( = {}, &block) = { row_names: true }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id| config['graphType'] = 'Line' end return html_string end |
#load_css(css_files) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/report_html/report_html.rb', line 47 def load_css(css_files) loaded_css = [] css_files.each do |css_lib| loaded_css << File.open(File.join(JS_FOLDER, css_lib)).read end return loaded_css end |
#load_js_libraries(js_libraries) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/report_html/report_html.rb', line 38 def load_js_libraries(js_libraries) loaded_libraries = [] js_libraries.each do |js_lib| js_file = File.open(File.join(JS_FOLDER, js_lib)).read loaded_libraries << Base64.encode64(js_file) end return loaded_libraries end |
#make_head ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/report_html/report_html.rb', line 55 def make_head @all_report << "\t<title>#{@title}</title> <head> <meta charset=\"utf-8\"> <meta http-equiv=\"CACHE-CONTROL\" CONTENT=\"NO-CACHE\"> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <meta http-equiv=\"Content-Language\" content=\"en-us\" /> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n" # ADD JS LIBRARIES AND CSS js_libraries = [] css_files = [] if !@plots_data.empty? js_libraries << 'canvasXpress.min.js' css_files << 'canvasXpress.css' end if !@dt_tables.empty? || !@bs_tables.empty? #Bootstrap for datatables or only for static tables. Use bootstrap version needed by datatables to avoid incompatibility issues @all_report << '<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>'+"\n" end if !@dt_tables.empty? # CDN load, this library is difficult to embed in html file @all_report << '<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap.min.css"/>'+"\n" @all_report << '<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>' + "\n" @all_report << '<script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>' + "\n" @all_report << '<script type="text/javascript" src="https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap.min.js"></script>' + "\n" end loaded_js_libraries = load_js_libraries(js_libraries) loaded_css = load_css(css_files) loaded_css.each do |css| @all_report << "<style type=\"text/css\"/> #{css} </style>\n" end loaded_js_libraries.each do |lib| @all_report << "<script src=\"data:application/javascript;base64,#{lib}\" type=\"application/javascript\"></script>\n" end # ADD CUSTOM FUNCTIONS TO USE LOADED JS LIBRARIES #canvasXpress objects if !@plots_data.empty? @all_report << "<script> var initPage = function () { <% @plots_data.each do |plot_data| %> <%= plot_data %> <% end %> } </script>" end #DT tables if !@dt_tables.empty? @all_report << "<script> <% @dt_tables.each do |dt_table| %> $(document).ready(function () { $('#<%= dt_table %>').DataTable(); }); <% end %> </script>\n" end @all_report << "</head>\n" end |
#pie(user_options = {}, &block) ⇒ Object
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/report_html/report_html.rb', line 496 def pie( = {}, &block) = { transpose: false }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id| config['graphType'] = 'Pie' if samples.length > 1 config['showPieGrid'] = true config['xAxis'] = samples config['layout'] = "#{(samples.length.to_f/2).ceil}X2" if config['layout'].nil? config['showPieSampleLabel'] = true if config['showPieSampleLabel'].nil? end end return html_string end |
#prepare_table_attribs(attribs) ⇒ Object
316 317 318 319 320 321 322 323 324 |
# File 'lib/report_html/report_html.rb', line 316 def prepare_table_attribs(attribs) attribs_string = '' if !attribs.empty? attribs.each do |attrib, value| attribs_string << "#{attrib}= \"#{value}\" " end end return attribs_string end |
#scatterbubble2D(user_options = {}, &block) ⇒ Object
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 |
# File 'lib/report_html/report_html.rb', line 547 def scatterbubble2D( = {}, &block) = { row_names: true, transpose: false }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id| config['graphType'] = 'ScatterBubble2D' if [:xAxis].nil? config['xAxis'] = [samples[0]] else config['xAxis'] = [:xAxis] end if [:yAxis].nil? config['yAxis'] = [samples[1]] else config['yAxis'] = [:yAxis] end if [:zAxis].nil? config['zAxis'] = [samples[2]] else config['zAxis'] = [:zAxis] end if [:y_label].nil? config['yAxisTitle'] = 'y_axis' else config['yAxisTitle'] = [:y_label] end if [:z_label].nil? config['zAxisTitle'] = 'z_axis' else config['zAxisTitle'] = [:z_label] end if ![:upper_limit].nil? && ![:lower_limit].nil? && ![:ranges].nil? diff = ([:upper_limit] - [:lower_limit]).to_f/[:ranges] sizes = Array.new([:ranges]) {|index| [:lower_limit] + index * diff} config['sizes'] = sizes end end return html_string end |
#sccater2D(user_options = {}, &block) ⇒ Object Also known as: scatter2D
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/report_html/report_html.rb', line 524 def sccater2D( = {}, &block) = { row_names: false, transpose: false }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id| config['graphType'] = 'Scatter2D' config['xAxis'] = [samples.first] if config['xAxis'].nil? config['yAxis'] = samples[1..samples.length-1] if config['yAxis'].nil? if [:y_label].nil? config['yAxisTitle'] = 'y_axis' else config['yAxisTitle'] = [:y_label] end if [:regressionLine] [:extracode] = "C#{object_id}.addRegressionLine();" end end return html_string end |
#set_tree(options, config) ⇒ Object
344 345 346 347 348 349 350 351 352 353 |
# File 'lib/report_html/report_html.rb', line 344 def set_tree(, config) tree = tree_from_file([:tree]) if [:treeBy] == 's' config['smpDendrogramNewick'] = tree config['samplesClustered'] = true elsif [:treeBy] == 'v' config['varDendrogramNewick'] = tree config['variablesClustered'] = true end end |
#stacked(user_options = {}, &block) ⇒ Object
451 452 453 454 455 456 457 458 459 |
# File 'lib/report_html/report_html.rb', line 451 def stacked( = {}, &block) = { row_names: true, }.merge!() html_string = canvasXpress_main(, block) do |, config, samples, vars, values, object_id| config['graphType'] = 'Stacked' end return html_string end |
#table(user_options = {}, &block) ⇒ Object
TABLE METHODS
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 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 263 264 265 266 267 |
# File 'lib/report_html/report_html.rb', line 215 def table( = {}, &block) = { id: nil, header: false, row_names: false, add_header_row_names: false, transpose: false, fields: [], border: 1, cell_align: [], attrib: {} } .merge!() table_attr = prepare_table_attribs([:attrib]) array_data = get_data() block.call(array_data) if !block.nil? rowspan, colspan = get_col_n_row_span(array_data) table_id = 'table_' + @count_objects.to_s @dt_tables << table_id if [:styled] == 'dt' @bs_tables << table_id if [:styled] == 'bs' tbody_tag = false html = " <table id=\"#{table_id}\" border=\"#{[:border]}\" #{table_attr}> <% if options[:header] %> <thead> <% end %> <% array_data.each_with_index do |row, i| %> <% if options[:header] && i == 1 %> <tbody> <% end %> <tr> <% row.each_with_index do |cell, j| if cell != 'colspan' && cell != 'rowspan' if i == 0 && options[:header] %> <th <%= get_span(colspan, rowspan, i, j) %>><%= cell %></th> <% else %> <td <%= get_cell_align(options[:cell_align], j) %> <%= get_span(colspan, rowspan, i, j) %>><%= cell %></td> <% end end %> <% end %> </tr> <% if i == 0 && options[:header] %> </thead> <% end %> <% end %> <% if options[:header] %> </tbody> <% end %> </table> " @count_objects += 1 return ERB.new(html).result(binding) end |
#tree_from_file(file) ⇒ Object
339 340 341 342 |
# File 'lib/report_html/report_html.rb', line 339 def tree_from_file(file) string_tree = File.open(file).read.gsub("\n", '') return string_tree end |
#write(file) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/report_html/report_html.rb', line 127 def write(file) #dir = File.dirname(file) string_report = get_report #FileUtils.cp_r(JS_FOLDER, dir) File.open(file, 'w'){|f| f.puts string_report} end |