diff options
| -rw-r--r-- | .rubocop_todo.yml | 45 | ||||
| -rw-r--r-- | lib/axlsx/drawing/area_series.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/drawing/bar_3D_chart.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/drawing/bar_chart.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/drawing/line_3D_chart.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/drawing/line_series.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/drawing/num_val.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/drawing/scatter_series.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/drawing/str_val.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/package.rb | 6 | ||||
| -rw-r--r-- | lib/axlsx/stylesheet/font.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/stylesheet/styles.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/util/validators.rb | 6 | ||||
| -rw-r--r-- | lib/axlsx/util/zip_command.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/workbook.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/border_creator.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/pivot_table.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/rich_text_run.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 8 |
19 files changed, 30 insertions, 75 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fc0449d9..2359f950 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -244,20 +244,6 @@ Style/MultipleComparison: - 'test/workbook/tc_workbook_view.rb' # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: both, prefix, postfix -Style/NegatedIf: - Exclude: - - 'lib/axlsx/drawing/num_val.rb' - - 'lib/axlsx/drawing/str_val.rb' - - 'lib/axlsx/package.rb' - - 'lib/axlsx/stylesheet/styles.rb' - - 'lib/axlsx/util/zip_command.rb' - - 'lib/axlsx/workbook/workbook.rb' - - 'lib/axlsx/workbook/worksheet/border_creator.rb' - - 'lib/axlsx/workbook/worksheet/worksheet.rb' - -# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, MinBodyLength. # SupportedStyles: skip_modifier_ifs, always Style/Next: @@ -308,14 +294,6 @@ Style/ParallelAssignment: - 'lib/axlsx/workbook/worksheet/row.rb' # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowSafeAssignment, AllowInMultilineConditions. -Style/ParenthesesAroundCondition: - Exclude: - - 'lib/axlsx/stylesheet/font.rb' - - 'lib/axlsx/util/validators.rb' - - 'lib/axlsx/workbook/worksheet/rich_text_run.rb' - -# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: PreferredDelimiters. Style/PercentLiteralDelimiters: Exclude: @@ -371,19 +349,6 @@ Style/RedundantInterpolation: - 'lib/axlsx/workbook/worksheet/worksheet.rb' # This cop supports safe autocorrection (--autocorrect). -Style/RedundantParentheses: - Exclude: - - 'lib/axlsx/drawing/area_series.rb' - - 'lib/axlsx/drawing/bar_3D_chart.rb' - - 'lib/axlsx/drawing/bar_chart.rb' - - 'lib/axlsx/drawing/line_3D_chart.rb' - - 'lib/axlsx/drawing/line_series.rb' - - 'lib/axlsx/drawing/scatter_series.rb' - - 'lib/axlsx/package.rb' - - 'lib/axlsx/workbook/worksheet/pivot_table.rb' - - 'lib/axlsx/workbook/worksheet/worksheet.rb' - -# This cop supports safe autocorrection (--autocorrect). Style/RedundantRegexpEscape: Exclude: - 'lib/axlsx/workbook/worksheet/pivot_table.rb' @@ -430,16 +395,6 @@ Style/SymbolArray: EnforcedStyle: brackets # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, AllowSafeAssignment. -# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex -Style/TernaryParentheses: - Exclude: - - 'lib/axlsx/drawing/area_series.rb' - - 'lib/axlsx/drawing/line_series.rb' - - 'lib/axlsx/drawing/scatter_series.rb' - - 'lib/axlsx/workbook/worksheet/rich_text_run.rb' - -# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, AllowedMethods. # AllowedMethods: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym Style/TrivialAccessors: diff --git a/lib/axlsx/drawing/area_series.rb b/lib/axlsx/drawing/area_series.rb index c43fe929..30bd9402 100644 --- a/lib/axlsx/drawing/area_series.rb +++ b/lib/axlsx/drawing/area_series.rb @@ -94,7 +94,7 @@ module Axlsx @labels.to_xml_string(str) unless @labels.nil? @data.to_xml_string(str) unless @data.nil? - str << '<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>' + str << '<c:smooth val="' << (smooth ? '1' : '0') << '"/>' end end diff --git a/lib/axlsx/drawing/bar_3D_chart.rb b/lib/axlsx/drawing/bar_3D_chart.rb index 604a9d17..4b688668 100644 --- a/lib/axlsx/drawing/bar_3D_chart.rb +++ b/lib/axlsx/drawing/bar_3D_chart.rb @@ -99,14 +99,14 @@ module Axlsx # space between bar or column clusters, as a percentage of the bar or column width. def gap_width=(v) RangeValidator.validate "Bar3DChart.gap_width", 0, 500, v - @gap_width = (v) + @gap_width = v end alias :gapWidth= :gap_width= # space between bar or column clusters, as a percentage of the bar or column width. def gap_depth=(v) RangeValidator.validate "Bar3DChart.gap_depth", 0, 500, v - @gap_depth = (v) + @gap_depth = v end alias :gapDepth= :gap_depth= diff --git a/lib/axlsx/drawing/bar_chart.rb b/lib/axlsx/drawing/bar_chart.rb index 87fd66c0..0dcf2c11 100644 --- a/lib/axlsx/drawing/bar_chart.rb +++ b/lib/axlsx/drawing/bar_chart.rb @@ -91,13 +91,13 @@ module Axlsx # space between bar or column clusters, as a percentage of the bar or column width. def gap_width=(v) RangeValidator.validate "BarChart.gap_width", 0, 500, v - @gap_width = (v) + @gap_width = v end alias :gapWidth= :gap_width= def overlap=(v) RangeValidator.validate "BarChart.overlap", -100, 100, v - @overlap = (v) + @overlap = v end # The shape of the bars or columns diff --git a/lib/axlsx/drawing/line_3D_chart.rb b/lib/axlsx/drawing/line_3D_chart.rb index 024ece0a..54f0170f 100644 --- a/lib/axlsx/drawing/line_3D_chart.rb +++ b/lib/axlsx/drawing/line_3D_chart.rb @@ -50,7 +50,7 @@ module Axlsx # @see gapDepth def gap_depth=(v) RegexValidator.validate "Line3DChart.gapWidth", GAP_AMOUNT_PERCENT, v - @gap_depth = (v) + @gap_depth = v end alias :gapDepth= :gap_depth= diff --git a/lib/axlsx/drawing/line_series.rb b/lib/axlsx/drawing/line_series.rb index d6a412e4..9f8e09e3 100644 --- a/lib/axlsx/drawing/line_series.rb +++ b/lib/axlsx/drawing/line_series.rb @@ -94,7 +94,7 @@ module Axlsx @labels.to_xml_string(str) unless @labels.nil? @data.to_xml_string(str) unless @data.nil? - str << '<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>' + str << '<c:smooth val="' << (smooth ? '1' : '0') << '"/>' end end diff --git a/lib/axlsx/drawing/num_val.rb b/lib/axlsx/drawing/num_val.rb index 19829a30..862d22ae 100644 --- a/lib/axlsx/drawing/num_val.rb +++ b/lib/axlsx/drawing/num_val.rb @@ -25,7 +25,7 @@ module Axlsx # serialize the object def to_xml_string(idx, str = +'') Axlsx::validate_unsigned_int(idx) - if !v.to_s.empty? + unless v.to_s.empty? str << '<c:pt idx="' << idx.to_s << '" formatCode="' << format_code << '"><c:v>' << v.to_s << '</c:v></c:pt>' end end diff --git a/lib/axlsx/drawing/scatter_series.rb b/lib/axlsx/drawing/scatter_series.rb index 2838c3de..a287a112 100644 --- a/lib/axlsx/drawing/scatter_series.rb +++ b/lib/axlsx/drawing/scatter_series.rb @@ -110,7 +110,7 @@ module Axlsx end @xData.to_xml_string(str) unless @xData.nil? @yData.to_xml_string(str) unless @yData.nil? - str << '<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>' + str << '<c:smooth val="' << (smooth ? '1' : '0') << '"/>' end str end diff --git a/lib/axlsx/drawing/str_val.rb b/lib/axlsx/drawing/str_val.rb index d09e6ce8..86663cec 100644 --- a/lib/axlsx/drawing/str_val.rb +++ b/lib/axlsx/drawing/str_val.rb @@ -25,7 +25,7 @@ module Axlsx # serialize the object def to_xml_string(idx, str = +'') Axlsx::validate_unsigned_int(idx) - if !v.to_s.empty? + unless v.to_s.empty? str << '<c:pt idx="' << idx.to_s << '"><c:v>' << ::CGI.escapeHTML(v.to_s) << '</c:v></c:pt>' end end diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index 26f838f8..4597efc0 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -101,7 +101,7 @@ module Axlsx # s = p.to_stream() # File.open('example_streamed.xlsx', 'wb') { |f| f.write(s.read) } def serialize(output, options = {}, secondary_options = nil) - if !workbook.styles_applied + unless workbook.styles_applied workbook.apply_styles end @@ -126,7 +126,7 @@ module Axlsx # @param [Boolean] confirm_valid Validate the package prior to serialization. # @return [StringIO|Boolean] False if confirm_valid and validation errors exist. rewound string IO if not. def to_stream(confirm_valid = false) - if !workbook.styles_applied + unless workbook.styles_applied workbook.apply_styles end @@ -266,7 +266,7 @@ module Axlsx [ { entry: CONTENT_TYPES_PN, doc: content_types, schema: CONTENT_TYPES_XSD }, { entry: RELS_PN, doc: relationships, schema: RELS_XSD }, - *(parts.sort_by { |part| part[:entry] }.reverse) + *parts.sort_by { |part| part[:entry] }.reverse ] end diff --git a/lib/axlsx/stylesheet/font.rb b/lib/axlsx/stylesheet/font.rb index 8b183b6e..2d9647af 100644 --- a/lib/axlsx/stylesheet/font.rb +++ b/lib/axlsx/stylesheet/font.rb @@ -124,8 +124,8 @@ module Axlsx # @see u def u=(v) - v = :single if (v == true || v == 1 || v == :true || v == 'true') - v = :none if (v == false || v == 0 || v == :false || v == 'false') + v = :single if v == true || v == 1 || v == :true || v == 'true' + v = :none if v == false || v == 0 || v == :false || v == 'false' Axlsx::validate_cell_u v @u = v end diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index e518d21e..6356d9e6 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -381,7 +381,7 @@ module Axlsx end validate_border_hash = ->(val) { - if !(val.key?(:style) && val.key?(:color)) + unless val.key?(:style) && val.key?(:color) raise ArgumentError, (ERR_INVALID_BORDER_OPTIONS % options[:border]) end } @@ -439,7 +439,7 @@ module Axlsx next end - if !edge_b_opts.empty? + unless edge_b_opts.empty? if base_border_opts.empty? validate_border_hash.call(edge_b_opts) end diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb index 695d28ad..48c12c13 100644 --- a/lib/axlsx/util/validators.rb +++ b/lib/axlsx/util/validators.rb @@ -41,7 +41,7 @@ module Axlsx # @param [Regexp] regex The regular expression to evaluate # @param [Any] v The value to validate. def self.validate(name, regex, v) - raise ArgumentError, (ERR_REGEX % [v.inspect, regex.to_s]) unless (v.respond_to?(:to_s) && regex.match?(v.to_s)) + raise ArgumentError, (ERR_REGEX % [v.inspect, regex.to_s]) unless v.respond_to?(:to_s) && regex.match?(v.to_s) end end @@ -71,7 +71,7 @@ module Axlsx # @para, [Any] v the value to validate # @raise [ArgumentError] raised if the value cannot be converted to an integer def self.validate_integerish(v) - raise ArgumentError, (ERR_INTEGERISH % v.inspect) unless (v.respond_to?(:to_i) && v.to_i.is_a?(Integer)) + raise ArgumentError, (ERR_INTEGERISH % v.inspect) unless v.respond_to?(:to_i) && v.to_i.is_a?(Integer) end # Requires that the value is between -54000000 and 54000000 @@ -79,7 +79,7 @@ module Axlsx # @raise [ArgumentError] raised if the value cannot be converted to an integer between the allowed angle values for chart label rotation. # @return [Boolean] true if the data is valid def self.validate_angle(v) - raise ArgumentError, (ERR_ANGLE % v.inspect) unless (v.to_i >= -5400000 && v.to_i <= 5400000) + raise ArgumentError, (ERR_ANGLE % v.inspect) unless v.to_i >= -5400000 && v.to_i <= 5400000 end # Validates an unsigned intger diff --git a/lib/axlsx/util/zip_command.rb b/lib/axlsx/util/zip_command.rb index 44e06af5..77cc44c7 100644 --- a/lib/axlsx/util/zip_command.rb +++ b/lib/axlsx/util/zip_command.rb @@ -63,7 +63,7 @@ module Axlsx escaped_dir = Shellwords.shellescape(@dir) command = "cd #{escaped_dir} && #{@zip_command} #{output} #{inputs}" stdout_and_stderr, status = Open3.capture2e(command) - if !status.success? + unless status.success? raise ZipError, stdout_and_stderr end end diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index e6e2f06f..271d4300 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -197,7 +197,7 @@ module Axlsx # A helper to apply styles that were added using `worksheet.add_style` # @return [Boolean] def apply_styles - return false if !styled_cells + return false unless styled_cells styled_cells.each do |cell| current_style = styles.style_index[cell.style] diff --git a/lib/axlsx/workbook/worksheet/border_creator.rb b/lib/axlsx/workbook/worksheet/border_creator.rb index 9abaded5..04a9cfac 100644 --- a/lib/axlsx/workbook/worksheet/border_creator.rb +++ b/lib/axlsx/workbook/worksheet/border_creator.rb @@ -17,7 +17,7 @@ module Axlsx else @edges = @edges.map { |x| x&.to_sym }.uniq - if !(@edges - Axlsx::Border::EDGES).empty? + unless (@edges - Axlsx::Border::EDGES).empty? raise ArgumentError, "Invalid edges provided, #{edges}" end end diff --git a/lib/axlsx/workbook/worksheet/pivot_table.rb b/lib/axlsx/workbook/worksheet/pivot_table.rb index a75842cd..aca3ccb5 100644 --- a/lib/axlsx/workbook/worksheet/pivot_table.rb +++ b/lib/axlsx/workbook/worksheet/pivot_table.rb @@ -245,7 +245,7 @@ module Axlsx str << "<dataFields count=\"#{data.size}\">" data.each do |datum_value| # The correct name prefix in ["Sum","Average", etc...] - str << "<dataField name='#{(datum_value[:subtotal] || '')} of #{datum_value[:ref]}' fld='#{header_index_of(datum_value[:ref])}' baseField='0' baseItem='0'" + str << "<dataField name='#{datum_value[:subtotal] || ''} of #{datum_value[:ref]}' fld='#{header_index_of(datum_value[:ref])}' baseField='0' baseItem='0'" str << " numFmtId='#{datum_value[:num_fmt]}'" if datum_value[:num_fmt] str << " subtotal='#{datum_value[:subtotal]}' " if datum_value[:subtotal] str << "/>" diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb index 9f66959a..dac27752 100644 --- a/lib/axlsx/workbook/worksheet/rich_text_run.rb +++ b/lib/axlsx/workbook/worksheet/rich_text_run.rb @@ -130,7 +130,7 @@ module Axlsx # @see u def u=(v) - v = :single if (v == true || v == 1 || v == :true || v == 'true') + v = :single if v == true || v == 1 || v == :true || v == 'true' set_run_style :validate_cell_u, :u, v end @@ -242,7 +242,7 @@ module Axlsx return sz if sz font = styles.fonts[styles.cellXfs[style].fontId] || styles.fonts[0] - (font.b || (defined?(@b) && @b)) ? (font.sz * 1.5) : font.sz + font.b || (defined?(@b) && @b) ? (font.sz * 1.5) : font.sz end def style diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 90461c66..29a22db1 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -584,7 +584,7 @@ module Axlsx # @param [String|Array] cell_refs Cell references # @param [Hash] styles def add_style(cell_refs, *styles) - if !cell_refs.is_a?(Array) + unless cell_refs.is_a?(Array) cell_refs = [cell_refs] end @@ -613,7 +613,7 @@ module Axlsx border_edges = options end - if !cell_refs.is_a?(Array) + unless cell_refs.is_a?(Array) cell_refs = [cell_refs] end @@ -753,7 +753,7 @@ module Axlsx def validate_sheet_name(name) DataTypeValidator.validate :worksheet_name, String, name # ignore first character (BOM) after encoding to utf16 because Excel does so, too. - raise ArgumentError, (ERR_SHEET_NAME_EMPTY) if name.empty? + raise ArgumentError, ERR_SHEET_NAME_EMPTY if name.empty? character_length = name.encode("utf-16")[1..-1].encode("utf-16").bytesize / 2 raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if character_length > WORKSHEET_MAX_NAME_LENGTH @@ -850,7 +850,7 @@ module Axlsx end def add_autofilter_defined_name_to_workbook - return if !auto_filter.range + return unless auto_filter.range workbook.add_defined_name auto_filter.defined_name, name: '_xlnm._FilterDatabase', local_sheet_id: index, hidden: 1 end |
