Class: Cuker::SummaryRubyXLFile
- Inherits:
-
RubyXLFile
- Object
- AbstractFile
- RubyXLFile
- Cuker::SummaryRubyXLFile
- Defined in:
- lib/cuker/helpers/writers/summary_x_l_writer.rb
Instance Attribute Summary collapse
-
#workbook ⇒ Object
Returns the value of attribute workbook.
-
#worksheet ⇒ Object
Returns the value of attribute worksheet.
-
#worksheets ⇒ Object
Returns the value of attribute worksheets.
Attributes inherited from AbstractFile
Attributes included from LoggerSetup
Instance Method Summary collapse
- #add_row(ary) ⇒ Object (also: #add_line)
- #current_col ⇒ Object
- #current_row ⇒ Object
-
#initialize(file_name, template_file_name) ⇒ SummaryRubyXLFile
constructor
A new instance of SummaryRubyXLFile.
- #locate_sheet(sheet_name) ⇒ Object
Methods inherited from RubyXLFile
Methods inherited from AbstractFile
Methods included from LoggerSetup
#init_logger, reset_appender_log_levels
Constructor Details
#initialize(file_name, template_file_name) ⇒ SummaryRubyXLFile
Returns a new instance of SummaryRubyXLFile.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cuker/helpers/writers/summary_x_l_writer.rb', line 35 def initialize file_name, template_file_name premade = File.basename(file_name) =~ /xlsm/ template_file_path = File.join File.dirname(__FILE__), template_file_name @file_name = premade ? template_file_path : file_name # super @file_name #replaced below init_logger @name = file_name @rows = [] @log.debug "Making new #{self.class} => #{@file_name}" @workbook = premade ? RubyXL::Parser.parse(@file_name) : RubyXL::Workbook.new @worksheets = @workbook.worksheets @worksheet = @workbook['Feature Summary raw'] @rows = sheet_rows.dup # starting Row @offset = 0 # starting Col @file_name = file_name end |
Instance Attribute Details
#workbook ⇒ Object
Returns the value of attribute workbook.
33 34 35 |
# File 'lib/cuker/helpers/writers/summary_x_l_writer.rb', line 33 def workbook @workbook end |
#worksheet ⇒ Object
Returns the value of attribute worksheet.
33 34 35 |
# File 'lib/cuker/helpers/writers/summary_x_l_writer.rb', line 33 def worksheet @worksheet end |
#worksheets ⇒ Object
Returns the value of attribute worksheets.
33 34 35 |
# File 'lib/cuker/helpers/writers/summary_x_l_writer.rb', line 33 def worksheets @worksheets end |
Instance Method Details
#add_row(ary) ⇒ Object Also known as: add_line
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/cuker/helpers/writers/summary_x_l_writer.rb', line 80 def add_row ary # super ary @rows << ary row, col = current_row, current_col worksheet.insert_row(row) ary.each do |val| case val.class.to_s when "String", "Integer", /Nil/ worksheet.insert_cell(row, col, val) else @log.error "SummaryRubyXLFile auto stringification of unknown format: #{val.class} => '#{val}'" worksheet.insert_cell(row, col, val.to_s) # worksheet.insert_cell(row, col, val.to_s) end col += 1 end @log.trace workbook.worksheets.map(&:sheet_name) end |
#current_col ⇒ Object
76 77 78 |
# File 'lib/cuker/helpers/writers/summary_x_l_writer.rb', line 76 def current_col @offset end |
#current_row ⇒ Object
72 73 74 |
# File 'lib/cuker/helpers/writers/summary_x_l_writer.rb', line 72 def current_row rows.size - 1 end |
#locate_sheet(sheet_name) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cuker/helpers/writers/summary_x_l_writer.rb', line 59 def locate_sheet sheet_name sheet_index = @workbook.worksheets.index {|x| x.sheet_name == sheet_name} @link_sheet = @workbook.worksheets[sheet_index] if sheet_index @log.debug "located sheet #{sheet_name} @location #{sheet_index}" # @workbook.worksheets.delete_at(sheet_index) sheet_index else @log.error "no sheet named '#{sheet_name}' found.. available sheets []" nil end end |