summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.rubocop_todo.yml23
-rw-r--r--lib/axlsx.rb46
-rw-r--r--lib/axlsx/util/constants.rb2
-rw-r--r--test/tc_axlsx.rb2
4 files changed, 27 insertions, 46 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 2385ecb2..bc046dff 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -20,7 +20,6 @@ Layout/FirstHashElementIndentation:
Layout/HashAlignment:
Exclude:
- 'lib/axlsx/workbook/worksheet/border_creator.rb'
- - 'test/tc_axlsx.rb'
# This cop supports safe autocorrection (--autocorrect).
Lint/AmbiguousOperatorPrecedence:
@@ -69,7 +68,6 @@ Lint/NonLocalExitFromIterator:
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Exclude:
- - 'lib/axlsx.rb'
- 'lib/axlsx/drawing/axes.rb'
- 'lib/axlsx/workbook/worksheet/pivot_table.rb'
- 'lib/axlsx/workbook/worksheet/sheet_view.rb'
@@ -119,7 +117,6 @@ Performance/RedundantBlockCall:
# This cop supports safe autocorrection (--autocorrect).
Performance/RedundantMatch:
Exclude:
- - 'lib/axlsx.rb'
- 'lib/axlsx/stylesheet/color.rb'
- 'lib/axlsx/workbook/workbook.rb'
@@ -266,7 +263,6 @@ Style/GuardClause:
# Configuration parameters: AllowSplatArgument.
Style/HashConversion:
Exclude:
- - 'lib/axlsx.rb'
- 'lib/axlsx/workbook/worksheet/cell_serializer.rb'
- 'lib/axlsx/workbook/worksheet/rich_text_run.rb'
@@ -321,7 +317,6 @@ Style/LineEndConcatenation:
# Configuration parameters: AllowMethodComparison.
Style/MultipleComparison:
Exclude:
- - 'lib/axlsx.rb'
- 'lib/axlsx/stylesheet/font.rb'
- 'lib/axlsx/workbook/worksheet/cell.rb'
- 'lib/axlsx/workbook/worksheet/rich_text_run.rb'
@@ -449,7 +444,6 @@ Style/PercentLiteralDelimiters:
# This cop supports safe autocorrection (--autocorrect).
Style/PerlBackrefs:
Exclude:
- - 'lib/axlsx.rb'
- 'test/workbook/worksheet/tc_sheet_protection.rb'
# This cop supports unsafe autocorrection (--autocorrect-all).
@@ -471,7 +465,6 @@ Style/QuotedSymbols:
# SupportedStyles: compact, exploded
Style/RaiseArgs:
Exclude:
- - 'lib/axlsx.rb'
- 'lib/axlsx/package.rb'
- 'lib/axlsx/util/zip_command.rb'
- 'lib/axlsx/workbook/worksheet/border_creator.rb'
@@ -490,7 +483,6 @@ Style/RedundantCondition:
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantFileExtensionInRequire:
Exclude:
- - 'lib/axlsx.rb'
- 'lib/axlsx/content_type/content_type.rb'
- 'lib/axlsx/drawing/drawing.rb'
- 'lib/axlsx/rels/relationships.rb'
@@ -528,7 +520,6 @@ Style/RedundantParentheses:
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantRegexpEscape:
Exclude:
- - 'lib/axlsx.rb'
- 'lib/axlsx/workbook/worksheet/pivot_table.rb'
- 'lib/axlsx/workbook/worksheet/table.rb'
@@ -536,7 +527,6 @@ Style/RedundantRegexpEscape:
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
Exclude:
- - 'lib/axlsx.rb'
- 'lib/axlsx/package.rb'
- 'lib/axlsx/stylesheet/styles.rb'
- 'lib/axlsx/workbook/worksheet/worksheet.rb'
@@ -552,13 +542,6 @@ Style/RegexpLiteral:
Exclude:
- 'lib/axlsx/workbook/worksheet/cell.rb'
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: implicit, explicit
-Style/RescueStandardError:
- Exclude:
- - 'lib/axlsx.rb'
-
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
# AllowedMethods: present?, blank?, presence, try, try!
@@ -578,7 +561,6 @@ Style/SingleLineMethods:
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/SlicingWithRange:
Exclude:
- - 'lib/axlsx.rb'
- 'lib/axlsx/drawing/area_chart.rb'
- 'lib/axlsx/drawing/line_chart.rb'
- 'lib/axlsx/workbook/worksheet/pivot_table.rb'
@@ -656,11 +638,6 @@ Style/UnpackFirst:
- 'lib/axlsx/workbook/worksheet/sheet_protection.rb'
# This cop supports safe autocorrection (--autocorrect).
-Style/WhileUntilDo:
- Exclude:
- - 'lib/axlsx.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
Style/WhileUntilModifier:
Exclude:
- 'lib/axlsx/workbook/worksheet/color_scale.rb'
diff --git a/lib/axlsx.rb b/lib/axlsx.rb
index 6e6a317d..30683458 100644
--- a/lib/axlsx.rb
+++ b/lib/axlsx.rb
@@ -1,29 +1,29 @@
# frozen_string_literal: true
require 'htmlentities'
-require 'axlsx/version.rb'
+require 'axlsx/version'
require 'marcel'
-require 'axlsx/util/simple_typed_list.rb'
-require 'axlsx/util/constants.rb'
-require 'axlsx/util/validators.rb'
-require 'axlsx/util/accessors.rb'
+require 'axlsx/util/simple_typed_list'
+require 'axlsx/util/constants'
+require 'axlsx/util/validators'
+require 'axlsx/util/accessors'
require 'axlsx/util/serialized_attributes'
require 'axlsx/util/options_parser'
require 'axlsx/util/mime_type_utils'
require 'axlsx/util/buffered_zip_output_stream'
require 'axlsx/util/zip_command'
-require 'axlsx/stylesheet/styles.rb'
+require 'axlsx/stylesheet/styles'
-require 'axlsx/doc_props/app.rb'
-require 'axlsx/doc_props/core.rb'
-require 'axlsx/content_type/content_type.rb'
-require 'axlsx/rels/relationships.rb'
+require 'axlsx/doc_props/app'
+require 'axlsx/doc_props/core'
+require 'axlsx/content_type/content_type'
+require 'axlsx/rels/relationships'
-require 'axlsx/drawing/drawing.rb'
-require 'axlsx/workbook/workbook.rb'
-require 'axlsx/package.rb'
+require 'axlsx/drawing/drawing'
+require 'axlsx/workbook/workbook'
+require 'axlsx/package'
# required gems
require 'nokogiri'
require 'zip'
@@ -35,9 +35,9 @@ require 'time'
begin
if Gem.loaded_specs.has_key?("axlsx_styler")
- raise StandardError.new("Please remove `axlsx_styler` from your Gemfile, the associated functionality is now built-in to `caxlsx` directly.")
+ raise StandardError, "Please remove `axlsx_styler` from your Gemfile, the associated functionality is now built-in to `caxlsx` directly."
end
-rescue
+rescue StandardError
# Do nothing
end
@@ -53,7 +53,7 @@ module Axlsx
#
# Defining as a class method on Axlsx to refrain from monkeypatching Object for all users of this gem.
def self.instance_values_for(object)
- Hash[object.instance_variables.map { |name| [name.to_s[1..-1], object.instance_variable_get(name)] }]
+ object.instance_variables.to_h { |name| [name.to_s[1..], object.instance_variable_get(name)] }
end
# determines the cell range for the items provided
@@ -105,7 +105,7 @@ module Axlsx
row_index = (numbers_str.to_i - 1)
- return [col_index, row_index]
+ [col_index, row_index]
end
# converts the column index into alphabetical values.
@@ -147,9 +147,9 @@ module Axlsx
# @param [String] range A cell range, for example A1:D5
# @return [Array]
def self.range_to_a(range)
- range.match(/^(\w+?\d+)\:(\w+?\d+)$/)
- start_col, start_row = name_to_indices($1)
- end_col, end_row = name_to_indices($2)
+ range =~ /^(\w+?\d+):(\w+?\d+)$/
+ start_col, start_row = name_to_indices(::Regexp.last_match(1))
+ end_col, end_row = name_to_indices(::Regexp.last_match(2))
(start_row..end_row).to_a.map do |row_num|
(start_col..end_col).to_a.map do |col_num|
cell_r(col_num, row_num)
@@ -163,7 +163,7 @@ module Axlsx
def self.camel(s = "", all_caps = true)
s = s.to_s
s = s.capitalize if all_caps
- s.gsub(/_(.)/) { $1.upcase }
+ s.gsub(/_(.)/) { ::Regexp.last_match(1).upcase }
end
# returns the provided string with all invalid control charaters
@@ -184,7 +184,7 @@ module Axlsx
# @param [Object] value The value to process
# @return [Object]
def self.booleanize(value)
- if value == true || value == false
+ if BOOLEAN_VALUES.include?(value)
value ? 1 : 0
else
value
@@ -195,7 +195,7 @@ module Axlsx
# @param [Hash] Hash to merge into
# @param [Hash] Hash to be added
def self.hash_deep_merge(first_hash, second_hash)
- first_hash.merge(second_hash) do |key, this_val, other_val|
+ first_hash.merge(second_hash) do |_key, this_val, other_val|
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
Axlsx.hash_deep_merge(this_val, other_val)
else
diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb
index 4697bb3a..af8d9702 100644
--- a/lib/axlsx/util/constants.rb
+++ b/lib/axlsx/util/constants.rb
@@ -413,4 +413,6 @@ module Axlsx
# Numeric recognition
NUMERIC_REGEX = /\A[+-]?\d+?\Z/.freeze
+
+ BOOLEAN_VALUES = [true, false].freeze
end
diff --git a/test/tc_axlsx.rb b/test/tc_axlsx.rb
index a70722ee..3c4b5f93 100644
--- a/test/tc_axlsx.rb
+++ b/test/tc_axlsx.rb
@@ -3,6 +3,7 @@
require 'tc_helper'
class TestAxlsx < Test::Unit::TestCase
+ # rubocop:disable Layout/HashAlignment
def setup_wide
@wide_test_points = {
"A3" => 0,
@@ -15,6 +16,7 @@ class TestAxlsx < Test::Unit::TestCase
"BZU3" => (2 * (26**2)) + (26 * 26) + 20
}
end
+ # rubocop:enable Layout/HashAlignment
def test_cell_range_empty_if_no_cell
assert_equal("", Axlsx.cell_range([]))