Class: GasLoadTester::ChartBuilder
- Inherits:
-
Object
- Object
- GasLoadTester::ChartBuilder
- Includes:
- Chartkick::Helper
- Defined in:
- lib/gas_load_tester/chart_builder.rb
Constant Summary collapse
- DEFAULT_PAGE_HEAD =
"<!DOCTYPE html>"\ "<html>"\ "<head>"\ "<script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>"\ "<script src=\"https://www.gstatic.com/charts/loader.js\"></script>"\ "<script src=\"https://ankane.github.io/chartkick.js/chartkick.js\"></script>"\ "</head>"\ "<body>"
- DEFAULT_PAGE_TAIL =
"<div style=\"display: block; height: 70px; width: 100%;\"></div>"\ "</body>"\ "</html>"
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#description ⇒ Object
Returns the value of attribute description.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#header ⇒ Object
Returns the value of attribute header.
Instance Method Summary collapse
- #build_body(test) ⇒ Object
- #build_group_body(group_test) ⇒ Object
-
#initialize(args = {}) ⇒ ChartBuilder
constructor
A new instance of ChartBuilder.
- #save ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ ChartBuilder
Returns a new instance of ChartBuilder.
23 24 25 26 27 28 29 30 31 |
# File 'lib/gas_load_tester/chart_builder.rb', line 23 def initialize(args = {}) args ||= {} args[:file_name] ||= args['file_name'] args[:header] ||= args['header'] args[:description] ||= args['description'] self.file_name = args[:file_name] self.header = args[:header] self.description = args[:description] end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
8 9 10 |
# File 'lib/gas_load_tester/chart_builder.rb', line 8 def body @body end |
#description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/gas_load_tester/chart_builder.rb', line 8 def description @description end |
#file_name ⇒ Object
Returns the value of attribute file_name.
8 9 10 |
# File 'lib/gas_load_tester/chart_builder.rb', line 8 def file_name @file_name end |
#header ⇒ Object
Returns the value of attribute header.
8 9 10 |
# File 'lib/gas_load_tester/chart_builder.rb', line 8 def header @header end |
Instance Method Details
#build_body(test) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/gas_load_tester/chart_builder.rb', line 44 def build_body(test) header_part = build_headpart || "" sum_body = build_sum_test(test) self.body = DEFAULT_PAGE_HEAD + header_part + sum_body + DEFAULT_PAGE_TAIL end |
#build_group_body(group_test) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/gas_load_tester/chart_builder.rb', line 52 def build_group_body(group_test) header_part = build_headpart || "" sum_group_body = group_test.tests.select{|test| test.is_run? }.collect{|test| build_sum_test(test) }.join('<hr style="margin-top: 70px; margin-bottom: 70px;">') sum_group_table = build_sum_group_table(group_test) self.body = DEFAULT_PAGE_HEAD + header_part + sum_group_table + sum_group_body + DEFAULT_PAGE_TAIL end |
#save ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gas_load_tester/chart_builder.rb', line 33 def save file_name = self.file_name if file_name == "" file_name = "load_result_"+Time.now.to_i.to_s+".html" elsif !file_name.end_with?(".html") file_name = file_name+".html" end File.open(file_name, 'w') { |file| file.write(self.body) } file_name end |