diff options
Diffstat (limited to 'lib/axlsx')
28 files changed, 51 insertions, 58 deletions
diff --git a/lib/axlsx/drawing/area_series.rb b/lib/axlsx/drawing/area_series.rb index 5cebd7da..cf4aaf13 100644 --- a/lib/axlsx/drawing/area_series.rb +++ b/lib/axlsx/drawing/area_series.rb @@ -37,7 +37,7 @@ module Axlsx # @param [Chart] chart def initialize(chart, options = {}) @show_marker = false - @marker_symbol = options[:marker_symbol] ? options[:marker_symbol] : :default + @marker_symbol = options[:marker_symbol] || :default @smooth = false @labels, @data = nil, nil super(chart, options) diff --git a/lib/axlsx/drawing/d_lbls.rb b/lib/axlsx/drawing/d_lbls.rb index 29697378..8965599c 100644 --- a/lib/axlsx/drawing/d_lbls.rb +++ b/lib/axlsx/drawing/d_lbls.rb @@ -83,7 +83,7 @@ module Axlsx str << '</c:dLbls>' end - # nills out d_lbl_pos and show_leader_lines as these attributes, while valid in the spec actually chrash excel for any chart type other than pie charts. + # nills out d_lbl_pos and show_leader_lines as these attributes, while valid in the spec actually crash Excel for any chart type other than pie charts. def validate_attributes_for_chart_type return if [Pie3DChart, LineChart].include? @chart_type diff --git a/lib/axlsx/drawing/hyperlink.rb b/lib/axlsx/drawing/hyperlink.rb index 3fb97069..0d9eb4f7 100644 --- a/lib/axlsx/drawing/hyperlink.rb +++ b/lib/axlsx/drawing/hyperlink.rb @@ -15,7 +15,7 @@ module Axlsx # @option options [String] tgtFrame Target frame for opening hyperlink # @option options [String] invalidUrl supposedly use to store the href when we know it is an invalid resource. # @option options [String] href the target resource this hyperlink links to. This is actually stored on the relationship. - # @option options [String] action A string that can be used to perform specific actions. For excel please see this reference: http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx + # @option options [String] action A string that can be used to perform specific actions. For Excel please see this reference: https://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx # @option options [Boolean] endSnd terminate any sound events when processing this link # @option options [Boolean] history include this link in the list of visited links for the applications history. # @option options [Boolean] highlightClick indicate that the link has already been visited. @@ -40,7 +40,7 @@ module Axlsx alias :invalidUrl :invalid_url alias :invalidUrl= :invalid_url= - # An action to take when the link is clicked. The specification says "This can be used to specify a slide to be navigated to or a script of code to be run." but in most cases you will not need to do anything with this. MS does reserve a few interesting strings. @see http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx + # An action to take when the link is clicked. The specification says "This can be used to specify a slide to be navigated to or a script of code to be run." but in most cases you will not need to do anything with this. MS does reserve a few interesting strings. @see https://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx # @return [String] attr_accessor :action diff --git a/lib/axlsx/drawing/line_series.rb b/lib/axlsx/drawing/line_series.rb index bbd3957e..fbed4000 100644 --- a/lib/axlsx/drawing/line_series.rb +++ b/lib/axlsx/drawing/line_series.rb @@ -37,7 +37,7 @@ module Axlsx # @param [Chart] chart def initialize(chart, options = {}) @show_marker = false - @marker_symbol = options[:marker_symbol] ? options[:marker_symbol] : :default + @marker_symbol = options[:marker_symbol] || :default @smooth = false @labels, @data = nil, nil super(chart, options) diff --git a/lib/axlsx/drawing/title.rb b/lib/axlsx/drawing/title.rb index c3ca9632..2e4037fb 100644 --- a/lib/axlsx/drawing/title.rb +++ b/lib/axlsx/drawing/title.rb @@ -32,7 +32,6 @@ module Axlsx DataTypeValidator.validate 'Title.text', String, v @text = v @cell = nil - v end # @see text_size @@ -40,7 +39,6 @@ module Axlsx DataTypeValidator.validate 'Title.text_size', String, v @text_size = v @cell = nil - v end # @see cell @@ -48,7 +46,6 @@ module Axlsx DataTypeValidator.validate 'Title.text', Cell, v @cell = v @text = v.value.to_s - v end # Check if the title is empty. diff --git a/lib/axlsx/drawing/vml_drawing.rb b/lib/axlsx/drawing/vml_drawing.rb index 322ec680..364ce19a 100644 --- a/lib/axlsx/drawing/vml_drawing.rb +++ b/lib/axlsx/drawing/vml_drawing.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Axlsx - # a vml drawing used for comments in excel. + # a vml drawing used for comments in Excel. class VmlDrawing # creates a new Vml Drawing object. # @param [Comments] comments the comments object this drawing is associated with diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index b4116f76..3f225648 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -145,7 +145,7 @@ module Axlsx # Encrypt the package into a CFB using the password provided # This is not ready yet def encrypt(file_name, password) - return false + false # moc = MsOffCrypto.new(file_name, password) # moc.save end @@ -159,7 +159,7 @@ module Axlsx # # If by chance you are able to create a package that does not validate it indicates that the internal # validation is not robust enough and needs to be improved. Please report your errors to the gem author. - # @see http://www.ecma-international.org/publications/standards/Ecma-376.htm + # @see https://www.ecma-international.org/publications-and-standards/standards/ecma-376/ # @example # # The following will output any error messages found in serialization. # p = Axlsx::Package.new @@ -239,7 +239,7 @@ module Axlsx end workbook.comments.each do |comment| - if comment.size > 0 + unless comment.empty? parts << { :entry => "xl/#{comment.pn}", :doc => comment, :schema => SML_XSD } parts << { :entry => "xl/#{comment.vml_drawing.pn}", :doc => comment.vml_drawing, :schema => nil } end @@ -314,13 +314,13 @@ module Axlsx end workbook.comments.each do |comment| - if comment.size > 0 + unless comment.empty? c_types << Axlsx::Override.new(:PartName => "/xl/#{comment.pn}", :ContentType => COMMENT_CT) end end - if workbook.comments.size > 0 + unless workbook.comments.empty? c_types << Axlsx::Default.new(:Extension => "vml", :ContentType => VML_DRAWING_CT) end @@ -386,7 +386,7 @@ module Axlsx options.merge!(secondary_options || {}) invalid_keys = options.keys - [:confirm_valid, :zip_command] if invalid_keys.any? - raise ArgumentError.new("Invalid keyword arguments: #{invalid_keys}") + raise ArgumentError, "Invalid keyword arguments: #{invalid_keys}" end [options.fetch(:confirm_valid, false), options.fetch(:zip_command, nil)] diff --git a/lib/axlsx/rels/relationship.rb b/lib/axlsx/rels/relationship.rb index 14d15457..93cdc88b 100644 --- a/lib/axlsx/rels/relationship.rb +++ b/lib/axlsx/rels/relationship.rb @@ -43,7 +43,7 @@ module Axlsx end # The id of the relationship (eg. "rId123"). Most instances get their own unique id. - # However, some instances need to share the same id – see {#should_use_same_id_as?} + # However, some instances need to share the same id – see {#ids_cache_key} # for details. # @return [String] attr_reader :Id diff --git a/lib/axlsx/stylesheet/cell_style.rb b/lib/axlsx/stylesheet/cell_style.rb index 5dc9a90d..5cdb4842 100644 --- a/lib/axlsx/stylesheet/cell_style.rb +++ b/lib/axlsx/stylesheet/cell_style.rb @@ -39,7 +39,7 @@ module Axlsx # @return [Integer] attr_reader :iLevel - # Determines if this named style should show in the list of styles when using excel + # Determines if this named style should show in the list of styles when using Excel # @return [Boolean] attr_reader :hidden diff --git a/lib/axlsx/stylesheet/color.rb b/lib/axlsx/stylesheet/color.rb index 87308bb1..24fe3bc3 100644 --- a/lib/axlsx/stylesheet/color.rb +++ b/lib/axlsx/stylesheet/color.rb @@ -53,7 +53,7 @@ module Axlsx def rgb=(v) Axlsx::validate_string(v) v = v.upcase - v = v * 3 if v.size == 2 + v *= 3 if v.size == 2 v = v.rjust(8, 'FF') raise ArgumentError, "Invalid color rgb value: #{v}." unless /[0-9A-F]{8}/.match?(v) diff --git a/lib/axlsx/stylesheet/num_fmt.rb b/lib/axlsx/stylesheet/num_fmt.rb index 95d9a62b..4604d7bd 100644 --- a/lib/axlsx/stylesheet/num_fmt.rb +++ b/lib/axlsx/stylesheet/num_fmt.rb @@ -20,7 +20,7 @@ module Axlsx serializable_attributes :formatCode, :numFmtId # @return [String] The formatting to use for this number format. - # @see http://support.microsoft.com/kb/264372 + # @see https://support.microsoft.com/kb/264372 attr_reader :formatCode # @return [Integer] An unsigned integer referencing a standard or custom number format. diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index e8263b45..625f6a02 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -110,7 +110,7 @@ module Axlsx # @see Styles#add_style attr_reader :dxfs - # The collection of table styles that will be available to the user in the excel UI + # The collection of table styles that will be available to the user in the Excel UI # @return [SimpleTypedList] # @note The recommended way to manage styles is with add_style # @see Styles#add_style @@ -278,11 +278,9 @@ module Axlsx # Add styles to style_index cache for re-use style_index[xf_index] = raw_style - return xf_index + xf_index else - dxf_index = (dxfs << style) - - return dxf_index + dxfs << style end end @@ -457,9 +455,9 @@ module Axlsx end if options[:type] == :dxf - return border + border else - return borders << border + borders << border end end diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb index 5ef3ece1..138c8bf0 100644 --- a/lib/axlsx/util/constants.rb +++ b/lib/axlsx/util/constants.rb @@ -356,7 +356,7 @@ module Axlsx # x1F Information Separator One # # The following are not dealt with. - # If you have this in your data, expect excel to blow up! + # If you have this in your data, expect Excel to blow up! # # x7F Delete # x80 Control 0080 diff --git a/lib/axlsx/util/storage.rb b/lib/axlsx/util/storage.rb index 2ce0d8f5..1e12b2d4 100644 --- a/lib/axlsx/util/storage.rb +++ b/lib/axlsx/util/storage.rb @@ -63,7 +63,6 @@ module Axlsx def name=(v) @name = v.bytes.to_a << 0 @name_size = @name.size * 2 - @name end # The size of the stream diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb index e9cf13b6..72e3f2d8 100644 --- a/lib/axlsx/util/validators.rb +++ b/lib/axlsx/util/validators.rb @@ -55,9 +55,10 @@ module Axlsx # @return [Boolean] true if validation succeeds. # @see validate_boolean def self.validate(name, types, v, other = false) - if other.is_a?(Proc) - raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless other.call(v) + if other.is_a?(Proc) && !other.call(v) + raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) end + v_class = v.is_a?(Class) ? v : v.class Array(types).each do |t| return if v_class <= t diff --git a/lib/axlsx/util/zip_command.rb b/lib/axlsx/util/zip_command.rb index e43ba03d..bc098a92 100644 --- a/lib/axlsx/util/zip_command.rb +++ b/lib/axlsx/util/zip_command.rb @@ -64,7 +64,7 @@ module Axlsx command = "cd #{escaped_dir} && #{@zip_command} #{output} #{inputs}" stdout_and_stderr, status = Open3.capture2e(command) if !status.success? - raise(ZipError.new(stdout_and_stderr)) + raise ZipError, stdout_and_stderr end end end diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index 1a2f0488..95d3e4a7 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -221,8 +221,8 @@ module Axlsx # @param [String] name The name of the sheet you are looking for # @return [Worksheet] The sheet found, or nil def sheet_by_name(name) - index = @worksheets.index { |sheet| sheet.name == name } - @worksheets[index] if index + encoded_name = Axlsx.coder.encode(name) + @worksheets.find { |sheet| sheet.name == encoded_name } end # Creates a new Workbook. @@ -391,7 +391,7 @@ module Axlsx end # returns a range of cells in a worksheet - # @param [String] cell_def The excel style reference defining the worksheet and cells. The range must specify the sheet to + # @param [String] cell_def The Excel style reference defining the worksheet and cells. The range must specify the sheet to # retrieve the cells from. e.g. range('Sheet1!A1:B2') will return an array of four cells [A1, A2, B1, B2] while range('Sheet1!A1') will return a single Cell. # @return [Cell, Array] def [](cell_def) @@ -406,7 +406,7 @@ module Axlsx # @param [String] str # @return [String] def to_xml_string(str = +'') - add_worksheet(name: 'Sheet1') unless worksheets.size > 0 + add_worksheet(name: 'Sheet1') if worksheets.empty? str << '<?xml version="1.0" encoding="UTF-8"?>' str << '<workbook xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '">' str << '<workbookPr date1904="' << @@date1904.to_s << '"/>' diff --git a/lib/axlsx/workbook/worksheet/border_creator.rb b/lib/axlsx/workbook/worksheet/border_creator.rb index 6321916f..9abaded5 100644 --- a/lib/axlsx/workbook/worksheet/border_creator.rb +++ b/lib/axlsx/workbook/worksheet/border_creator.rb @@ -13,12 +13,12 @@ module Axlsx if @edges == :all @edges = Axlsx::Border::EDGES elsif [email protected]_a?(Array) - raise ArgumentError.new("Invalid edges provided, #{@edges}") + raise ArgumentError, "Invalid edges provided, #{@edges}" else @edges = @edges.map { |x| x&.to_sym }.uniq if !(@edges - Axlsx::Border::EDGES).empty? - raise ArgumentError.new("Invalid edges provided, #{edges}") + raise ArgumentError, "Invalid edges provided, #{edges}" end end end diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 4d1bae63..c978bde4 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -83,7 +83,7 @@ module Axlsx attr_accessor :raw_style # The index of the cellXfs item to be applied to this cell. - # @param [Hash] styles + # @param [Hash] style # @see Axlsx::Styles def add_style(style) self.raw_style ||= {} @@ -115,7 +115,7 @@ module Axlsx # automatically determed. # @see Cell#cell_type_from_value # @return [Symbol] The type of data this cell's value is cast to. - # @raise [ArgumentExeption] Cell.type must be one of [:date, time, :float, :integer, :string, :boolean] + # @raise [ArgumentError] Cell.type must be one of [:date, time, :float, :integer, :string, :boolean] # @note # If the value provided cannot be cast into the type specified, type is changed to :string and the following logic is applied. # :string to :integer or :float, type conversions always return 0 or 0.0 diff --git a/lib/axlsx/workbook/worksheet/cell_serializer.rb b/lib/axlsx/workbook/worksheet/cell_serializer.rb index f45d3c73..dceca7eb 100644 --- a/lib/axlsx/workbook/worksheet/cell_serializer.rb +++ b/lib/axlsx/workbook/worksheet/cell_serializer.rb @@ -26,7 +26,7 @@ module Axlsx def run_xml_string(cell, str = +'') if cell.is_text_run? valid = RichTextRun::INLINE_STYLES - [:value, :type] - data = Hash[Axlsx.instance_values_for(cell).map { |k, v| [k.to_sym, v] }] + data = Axlsx.instance_values_for(cell).transform_keys(&:to_sym) data = data.select { |key, value| valid.include?(key) && !value.nil? } RichText.new(cell.value.to_s, data).to_xml_string(str) elsif cell.contains_rich_text? diff --git a/lib/axlsx/workbook/worksheet/data_bar.rb b/lib/axlsx/workbook/worksheet/data_bar.rb index 108a5c16..482bd029 100644 --- a/lib/axlsx/workbook/worksheet/data_bar.rb +++ b/lib/axlsx/workbook/worksheet/data_bar.rb @@ -101,7 +101,6 @@ module Axlsx def color=(v) @color = v if v.is_a? Color self.color.rgb = v if v.is_a? String - @color end # Serialize this object to an xml string diff --git a/lib/axlsx/workbook/worksheet/data_validation.rb b/lib/axlsx/workbook/worksheet/data_validation.rb index eca90743..bc9bc527 100644 --- a/lib/axlsx/workbook/worksheet/data_validation.rb +++ b/lib/axlsx/workbook/worksheet/data_validation.rb @@ -243,8 +243,8 @@ module Axlsx str << key_value.first << '="' << Axlsx.booleanize(key_value.last).to_s << '"' end str << '>' - str << '<formula1>' << self.formula1 << '</formula1>' if @formula1 and valid_attributes.include?(:formula1) - str << '<formula2>' << self.formula2 << '</formula2>' if @formula2 and valid_attributes.include?(:formula2) + str << '<formula1>' << formula1 << '</formula1>' if formula1 && valid_attributes.include?(:formula1) + str << '<formula2>' << formula2 << '</formula2>' if formula2 && valid_attributes.include?(:formula2) str << '</dataValidation>' end diff --git a/lib/axlsx/workbook/worksheet/date_time_converter.rb b/lib/axlsx/workbook/worksheet/date_time_converter.rb index ffa2831a..e34ef055 100644 --- a/lib/axlsx/workbook/worksheet/date_time_converter.rb +++ b/lib/axlsx/workbook/worksheet/date_time_converter.rb @@ -3,9 +3,9 @@ require "date" module Axlsx - # The DateTimeConverter class converts both data and time types to their apprpriate excel serializations + # The DateTimeConverter class converts both data and time types to their apprpriate Excel serializations class DateTimeConverter - # The date_to_serial method converts Date objects to the equivelant excel serialized forms + # The date_to_serial method converts Date objects to the equivelant Excel serialized forms # @param [Date] date the date to be serialized # @return [Numeric] def self.date_to_serial(date) @@ -14,7 +14,7 @@ module Axlsx (offset_date - epoch).to_f end - # The time_to_serial methond converts a Time object its excel serialized form. + # The time_to_serial methond converts a Time object its Excel serialized form. # @param [Time] time the time to be serialized # @return [Numeric] def self.time_to_serial(time) diff --git a/lib/axlsx/workbook/worksheet/pivot_table.rb b/lib/axlsx/workbook/worksheet/pivot_table.rb index 27065e4b..44a50f19 100644 --- a/lib/axlsx/workbook/worksheet/pivot_table.rb +++ b/lib/axlsx/workbook/worksheet/pivot_table.rb @@ -135,7 +135,6 @@ module Axlsx end @data << data_field end - @data end # The pages diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb index 883d01d3..ffd2f941 100644 --- a/lib/axlsx/workbook/worksheet/rich_text_run.rb +++ b/lib/axlsx/workbook/worksheet/rich_text_run.rb @@ -207,7 +207,7 @@ module Axlsx # @return [String] def to_xml_string(str = +'') valid = RichTextRun::INLINE_STYLES - data = Hash[Axlsx.instance_values_for(self).map { |k, v| [k.to_sym, v] }] + data = Axlsx.instance_values_for(self).transform_keys(&:to_sym) data = data.select { |key, value| valid.include?(key) && !value.nil? } str << '<r><rPr>' diff --git a/lib/axlsx/workbook/worksheet/row_breaks.rb b/lib/axlsx/workbook/worksheet/row_breaks.rb index 56e8c4c6..21691f7a 100644 --- a/lib/axlsx/workbook/worksheet/row_breaks.rb +++ b/lib/axlsx/workbook/worksheet/row_breaks.rb @@ -13,7 +13,7 @@ module Axlsx # max and man values are fixed. # @see Break def add_break(options) - # force feed the excel default + # force feed the Excel default self << Break.new(options.merge(:max => 16383, :man => true)) last end diff --git a/lib/axlsx/workbook/worksheet/sheet_pr.rb b/lib/axlsx/workbook/worksheet/sheet_pr.rb index 86826f77..ea191fa0 100644 --- a/lib/axlsx/workbook/worksheet/sheet_pr.rb +++ b/lib/axlsx/workbook/worksheet/sheet_pr.rb @@ -82,7 +82,7 @@ module Axlsx def update_properties page_setup_pr.fit_to_page = worksheet.fit_to_page? - if worksheet.auto_filter.columns.size > 0 + unless worksheet.auto_filter.columns.empty? self.filter_mode = 1 self.enable_format_conditions_calculation = 1 end diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 21c53409..8c6e53b4 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -65,7 +65,7 @@ module Axlsx # Specifies the visible state of this sheet. Allowed states are # :visible, :hidden or :very_hidden. The default value is :visible. # - # Worksheets in the :hidden state can be shown using the sheet formatting properties in excel. + # Worksheets in the :hidden state can be shown using the sheet formatting properties in Excel. # :very_hidden sheets should be inaccessible to end users. # @param [Symbol] sheet_state The visible state for this sheet. def state=(sheet_state) @@ -173,7 +173,7 @@ module Axlsx @rows.transpose(&block) end - # A range that excel will apply an auto-filter to "A1:B3" + # A range that Excel will apply an auto-filter to "A1:B3" # This will turn filtering on for the cells in the range. # The first row is considered the header, while subsequent rows are considered to be data. # @return String @@ -519,7 +519,7 @@ module Axlsx end # Adds a page break (row break) to the worksheet - # @param cell A Cell object or excel style string reference indicating where the break + # @param cell A Cell object or Excel style string reference indicating where the break # should be added to the sheet. # @example # ws.add_page_break("A4") @@ -581,7 +581,7 @@ module Axlsx end # Set the style for cells in a specific column - # @param [String|Array] cell references + # @param [String|Array] cell_refs Cell references # @param [Hash] styles def add_style(cell_refs, *styles) if !cell_refs.is_a?(Array) @@ -602,8 +602,8 @@ module Axlsx end # Set the style for cells in a specific column - # @param [String|Array] cell references - # @param [Hash|Array|Symbol] border options + # @param [String|Array] cell_refs Cell references + # @param [Hash|Array|Symbol] options border options def add_border(cell_refs, options = nil) if options.is_a?(Hash) border_edges = options[:edges] @@ -661,7 +661,7 @@ module Axlsx r end - # Returns the cell or cells defined using excel style A1:B3 references. + # Returns the cell or cells defined using Excel style A1:B3 references. # @param [String|Integer] cell_def the string defining the cell or range of cells, or the rownumber # @return [Cell, Array] def [](cell_def) @@ -693,7 +693,7 @@ module Axlsx r = rows[row_index] if r - return r[col_index] + r[col_index] end end |
