summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/yard.yml32
-rw-r--r--.rubocop_todo.yml153
-rw-r--r--CHANGELOG.md2
-rw-r--r--README.md16
-rw-r--r--axlsx.gemspec2
-rw-r--r--examples/README.md2
-rw-r--r--examples/basic_formula_example.md2
-rw-r--r--examples/cached_formula_example.md2
-rw-r--r--examples/column_outlines_example.md2
-rw-r--r--examples/complex_example.md2
-rw-r--r--examples/defined_name_example.md2
-rw-r--r--examples/images/sort_state_example_1.pngbin0 -> 62716 bytes
-rw-r--r--examples/images/sort_state_example_2.pngbin0 -> 64787 bytes
-rw-r--r--examples/row_outlines_example.md2
-rw-r--r--examples/sort_state_example.md42
-rw-r--r--lib/axlsx.rb5
-rw-r--r--lib/axlsx/content_type/abstract_content_type.rb4
-rw-r--r--lib/axlsx/content_type/default.rb2
-rw-r--r--lib/axlsx/content_type/override.rb2
-rw-r--r--lib/axlsx/doc_props/app.rb44
-rw-r--r--lib/axlsx/doc_props/core.rb2
-rw-r--r--lib/axlsx/drawing/area_chart.rb2
-rw-r--r--lib/axlsx/drawing/area_series.rb8
-rw-r--r--lib/axlsx/drawing/axis.rb10
-rw-r--r--lib/axlsx/drawing/bar_3D_chart.rb4
-rw-r--r--lib/axlsx/drawing/bar_chart.rb4
-rw-r--r--lib/axlsx/drawing/cat_axis.rb6
-rw-r--r--lib/axlsx/drawing/chart.rb14
-rw-r--r--lib/axlsx/drawing/d_lbls.rb4
-rw-r--r--lib/axlsx/drawing/drawing.rb6
-rw-r--r--lib/axlsx/drawing/hyperlink.rb6
-rw-r--r--lib/axlsx/drawing/line_3D_chart.rb2
-rw-r--r--lib/axlsx/drawing/line_chart.rb2
-rw-r--r--lib/axlsx/drawing/line_series.rb8
-rw-r--r--lib/axlsx/drawing/marker.rb12
-rw-r--r--lib/axlsx/drawing/num_data.rb2
-rw-r--r--lib/axlsx/drawing/num_data_source.rb2
-rw-r--r--lib/axlsx/drawing/num_val.rb6
-rw-r--r--lib/axlsx/drawing/one_cell_anchor.rb4
-rw-r--r--lib/axlsx/drawing/pic.rb12
-rw-r--r--lib/axlsx/drawing/pie_series.rb2
-rw-r--r--lib/axlsx/drawing/scaling.rb2
-rw-r--r--lib/axlsx/drawing/scatter_series.rb8
-rw-r--r--lib/axlsx/drawing/ser_axis.rb4
-rw-r--r--lib/axlsx/drawing/series.rb2
-rw-r--r--lib/axlsx/drawing/series_title.rb4
-rw-r--r--lib/axlsx/drawing/str_val.rb4
-rw-r--r--lib/axlsx/drawing/title.rb4
-rw-r--r--lib/axlsx/drawing/view_3D.rb4
-rw-r--r--lib/axlsx/drawing/vml_drawing.rb2
-rw-r--r--lib/axlsx/drawing/vml_shape.rb2
-rw-r--r--lib/axlsx/package.rb14
-rw-r--r--lib/axlsx/rels/relationship.rb6
-rw-r--r--lib/axlsx/stylesheet/border.rb6
-rw-r--r--lib/axlsx/stylesheet/cell_alignment.rb18
-rw-r--r--lib/axlsx/stylesheet/cell_protection.rb4
-rw-r--r--lib/axlsx/stylesheet/cell_style.rb12
-rw-r--r--lib/axlsx/stylesheet/color.rb6
-rw-r--r--lib/axlsx/stylesheet/dxf.rb2
-rw-r--r--lib/axlsx/stylesheet/font.rb28
-rw-r--r--lib/axlsx/stylesheet/gradient_fill.rb6
-rw-r--r--lib/axlsx/stylesheet/gradient_stop.rb4
-rw-r--r--lib/axlsx/stylesheet/num_fmt.rb4
-rw-r--r--lib/axlsx/stylesheet/pattern_fill.rb2
-rw-r--r--lib/axlsx/stylesheet/styles.rb10
-rw-r--r--lib/axlsx/stylesheet/table_style.rb8
-rw-r--r--lib/axlsx/stylesheet/table_style_element.rb6
-rw-r--r--lib/axlsx/stylesheet/table_styles.rb6
-rw-r--r--lib/axlsx/stylesheet/xf.rb30
-rw-r--r--lib/axlsx/util/accessors.rb2
-rw-r--r--lib/axlsx/util/constants.rb5
-rw-r--r--lib/axlsx/util/options_parser.rb2
-rw-r--r--lib/axlsx/util/storage.rb4
-rw-r--r--lib/axlsx/util/validators.rb27
-rw-r--r--lib/axlsx/util/zip_command.rb2
-rw-r--r--lib/axlsx/workbook/defined_name.rb2
-rw-r--r--lib/axlsx/workbook/shared_strings_table.rb2
-rw-r--r--lib/axlsx/workbook/workbook.rb22
-rw-r--r--lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb65
-rw-r--r--lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb51
-rw-r--r--lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb56
-rw-r--r--lib/axlsx/workbook/worksheet/border_creator.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb50
-rw-r--r--lib/axlsx/workbook/worksheet/cell_serializer.rb14
-rw-r--r--lib/axlsx/workbook/worksheet/cfvo.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/color_scale.rb8
-rw-r--r--lib/axlsx/workbook/worksheet/comment.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/comments.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/conditional_formatting.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb30
-rw-r--r--lib/axlsx/workbook/worksheet/data_bar.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/data_validation.rb30
-rw-r--r--lib/axlsx/workbook/worksheet/date_time_converter.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/icon_set.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/merged_cells.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/page_margins.rb12
-rw-r--r--lib/axlsx/workbook/worksheet/page_setup.rb12
-rw-r--r--lib/axlsx/workbook/worksheet/pane.rb14
-rw-r--r--lib/axlsx/workbook/worksheet/pivot_table.rb8
-rw-r--r--lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/protected_ranges.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/rich_text_run.rb10
-rw-r--r--lib/axlsx/workbook/worksheet/row.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/row_breaks.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/selection.rb10
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_protection.rb10
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_view.rb16
-rw-r--r--lib/axlsx/workbook/worksheet/table.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/table_style_info.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb34
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet_comments.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet_drawing.rb6
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb4
-rw-r--r--test/content_type/tc_content_type.rb22
-rw-r--r--test/drawing/tc_d_lbls.rb2
-rw-r--r--test/drawing/tc_vml_drawing.rb6
-rw-r--r--test/tc_axlsx.rb16
-rw-r--r--test/tc_package.rb4
-rw-r--r--test/util/tc_mime_type_utils.rb6
-rw-r--r--test/workbook/tc_workbook.rb4
-rw-r--r--test/workbook/worksheet/auto_filter/tc_sort_condition.rb37
-rw-r--r--test/workbook/worksheet/auto_filter/tc_sort_state.rb36
-rw-r--r--test/workbook/worksheet/tc_cell.rb4
-rw-r--r--test/workbook/worksheet/tc_comment.rb2
-rw-r--r--test/workbook/worksheet/tc_comments.rb2
-rw-r--r--test/workbook/worksheet/tc_date_time_converter.rb12
-rw-r--r--test/workbook/worksheet/tc_pivot_table.rb6
-rw-r--r--test/workbook/worksheet/tc_sheet_protection.rb2
-rw-r--r--test/workbook/worksheet/tc_table_style_info.rb2
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb6
130 files changed, 771 insertions, 588 deletions
diff --git a/.github/workflows/yard.yml b/.github/workflows/yard.yml
new file mode 100644
index 00000000..61e27f46
--- /dev/null
+++ b/.github/workflows/yard.yml
@@ -0,0 +1,32 @@
+name: YARD
+
+on:
+ push:
+ branches: ['*']
+ pull_request:
+ branches: ['*']
+
+permissions:
+ contents: read
+
+jobs:
+ rubocop:
+ name: YARD
+ runs-on: ${{ matrix.os }}
+ env:
+ BUNDLE_JOBS: 4
+ BUNDLE_RETRY: 3
+ strategy:
+ matrix:
+ os: [ubuntu-latest]
+ ruby-version: ['3.2']
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up Ruby
+ uses: ruby/setup-ruby@v1
+ with:
+ ruby-version: ${{ matrix.ruby-version }}
+ bundler-cache: true
+ - name: Lint YARD documentation
+ run: bundle exec yard doc --fail-on-warning --no-output --no-progress
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 525fd031..6e233ce4 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -7,13 +7,6 @@
# versions of RuboCop, may require this file to be generated again.
# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: Severity, Include.
-# Include: **/*.gemspec
-Gemspec/RequireMFA:
- Exclude:
- - 'axlsx.gemspec'
-
-# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_braces
Layout/FirstHashElementIndentation:
@@ -31,7 +24,6 @@ Layout/HashAlignment:
# This cop supports safe autocorrection (--autocorrect).
Lint/AmbiguousOperatorPrecedence:
Exclude:
- - 'lib/axlsx/workbook/worksheet/sheet_protection.rb'
- 'lib/axlsx/workbook/worksheet/worksheet.rb'
# This cop supports unsafe autocorrection (--autocorrect-all).
@@ -56,10 +48,6 @@ Lint/DisjunctiveAssignmentInConstructor:
Exclude:
- 'lib/axlsx/drawing/num_data_source.rb'
-Lint/NonLocalExitFromIterator:
- Exclude:
- - 'lib/axlsx/util/validators.rb'
-
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
Lint/UnusedMethodArgument:
@@ -95,18 +83,6 @@ Naming/MethodName:
Naming/MethodParameterName:
Enabled: false
-# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
-# NamePrefix: is_, has_, have_
-# ForbiddenPrefixes: is_, has_, have_
-# AllowedMethods: is_a?
-# MethodDefinitionMacros: define_method, define_singleton_method
-Naming/PredicateName:
- Exclude:
- - 'spec/**/*'
- - 'lib/axlsx/workbook/worksheet/cell.rb'
- - 'lib/axlsx/workbook/worksheet/worksheet_comments.rb'
- - 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb'
-
# Configuration parameters: EnforcedStyle, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, camelCase
Naming/VariableName:
@@ -131,13 +107,6 @@ Naming/VariableNumber:
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
-# SupportedStyles: separated, grouped
-Style/AccessorGrouping:
- Exclude:
- - 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle.
# SupportedStyles: prefer_alias, prefer_alias_method
Style/Alias:
Enabled: false
@@ -148,10 +117,6 @@ Style/ClassVars:
- 'lib/axlsx/workbook/workbook.rb'
- 'lib/axlsx/workbook/worksheet/dimension.rb'
-# This cop supports safe autocorrection (--autocorrect).
-Style/ColonMethodCall:
- Enabled: false
-
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/ConcatArrayLiterals:
Exclude:
@@ -179,18 +144,6 @@ Style/ExpandPathArguments:
- 'axlsx.gemspec'
# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: format, sprintf, percent
-Style/FormatString:
- Exclude:
- - 'lib/axlsx/drawing/pic.rb'
- - 'lib/axlsx/drawing/view_3D.rb'
- - 'lib/axlsx/drawing/vml_drawing.rb'
- - 'lib/axlsx/util/accessors.rb'
- - 'lib/axlsx/util/validators.rb'
- - 'lib/axlsx/workbook/worksheet/worksheet.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, AllowedMethods, AllowedPatterns.
# SupportedStyles: annotated, template, unannotated
Style/FormatStringToken:
@@ -216,18 +169,6 @@ Style/IfUnlessModifier:
Enabled: false
# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: line_count_dependent, lambda, literal
-Style/Lambda:
- Exclude:
- - 'lib/axlsx/drawing/chart.rb'
- - 'lib/axlsx/drawing/scaling.rb'
- - 'lib/axlsx/stylesheet/gradient_fill.rb'
- - 'lib/axlsx/stylesheet/gradient_stop.rb'
- - 'lib/axlsx/stylesheet/styles.rb'
- - 'lib/axlsx/util/validators.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowMethodComparison.
Style/MultipleComparison:
Exclude:
@@ -236,20 +177,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:
@@ -266,11 +193,6 @@ Style/NumericPredicate:
- 'lib/axlsx/util/validators.rb'
- 'lib/axlsx/workbook/worksheet/worksheet.rb'
-# This cop supports safe autocorrection (--autocorrect).
-Style/OperatorMethodCall:
- Exclude:
- - 'lib/axlsx/drawing/vml_shape.rb'
-
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
@@ -300,14 +222,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:
@@ -326,18 +240,6 @@ Style/PercentLiteralDelimiters:
- 'test/workbook/worksheet/tc_table_style_info.rb'
# This cop supports safe autocorrection (--autocorrect).
-Style/PerlBackrefs:
- Exclude:
- - 'test/workbook/worksheet/tc_sheet_protection.rb'
-
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: short, verbose
-Style/PreferredHashMethods:
- Exclude:
- - 'lib/axlsx.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: same_as_string_literals, single_quotes, double_quotes
Style/QuotedSymbols:
@@ -345,46 +247,11 @@ Style/QuotedSymbols:
- 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb'
# This cop supports safe autocorrection (--autocorrect).
-Style/RandomWithOffset:
- Exclude:
- - 'lib/axlsx/drawing/vml_shape.rb'
-
-# This cop supports unsafe autocorrection (--autocorrect-all).
-Style/RedundantInterpolation:
- Exclude:
- - 'lib/axlsx/drawing/chart.rb'
- - 'lib/axlsx/drawing/drawing.rb'
- - 'lib/axlsx/drawing/pic.rb'
- - 'lib/axlsx/drawing/vml_drawing.rb'
- - 'lib/axlsx/workbook/worksheet/comments.rb'
- - 'lib/axlsx/workbook/worksheet/pivot_table.rb'
- - 'lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb'
- - 'lib/axlsx/workbook/worksheet/table.rb'
- - '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'
- 'lib/axlsx/workbook/worksheet/table.rb'
-# This cop supports safe autocorrection (--autocorrect).
-Style/RedundantSelf:
- Enabled: false
-
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
# AllowedMethods: present?, blank?, presence, try, try!
@@ -404,11 +271,6 @@ Style/SlicingWithRange:
- 'lib/axlsx/workbook/worksheet/pivot_table.rb'
- 'lib/axlsx/workbook/worksheet/worksheet.rb'
-# This cop supports unsafe autocorrection (--autocorrect-all).
-Style/StringChars:
- Exclude:
- - 'lib/axlsx/workbook/worksheet/sheet_protection.rb'
-
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
@@ -422,16 +284,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:
@@ -448,11 +300,6 @@ Style/TrivialAccessors:
- 'lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb'
# This cop supports safe autocorrection (--autocorrect).
-Style/UnpackFirst:
- Exclude:
- - 'lib/axlsx/workbook/worksheet/sheet_protection.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
Style/WhileUntilModifier:
Exclude:
- 'lib/axlsx/workbook/worksheet/color_scale.rb'
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7e0fc8b..d09e3196 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,8 @@ CHANGELOG
- Remove ability to set `u=` to true in favor of using :single or one of the other underline options
- Fix `Workbook#sheet_by_name` not returning sheets with encoded characters in the name
- Raise exception if `axlsx_styler` gem is present as its code was merged directly into `caxlsx` in v3.3.0
+ - Add 'SortState' and 'SortCondition' classes to the 'AutoFilter' class to add sorting to the generated file.
+ - [PR #189](https://github.com/caxlsx/caxlsx/pull/189) - Make `Axlsx::escape_formulas` true by default to mitigate [Formula Injection](https://www.owasp.org/index.php/CSV_Injection) vulnerabilities.
- **April.23.23**: 3.4.1
- [PR #209](https://github.com/caxlsx/caxlsx/pull/209) - Revert characters other than `=` being considered as formulas.
diff --git a/README.md b/README.md
index a77a99a9..93bfa07f 100644
--- a/README.md
+++ b/README.md
@@ -124,24 +124,20 @@ Currently the following additional gems are available:
## Security
-To prevent [Formula Injection](https://www.owasp.org/index.php/CSV_Injection) vulnerabilities, set the following in an initializer:
+To prevent [Formula Injection](https://www.owasp.org/index.php/CSV_Injection) vulnerabilities, as of version 4.0, axlsx escapes all formulas by default. To permit formulas on a specific cell, please use:
```ruby
-Axlsx.escape_formulas = true
+cell.escape_formulas = false
```
-Then, set the following on each cell you'd like to add a formula:
+You may set `escape_formulas` on the workbook, worksheet, row and/or cell level. Refer to examples/escape_formula.md for details.
+
+To allow formulas globally by default (which was the behavior in axlsx 3.x and prior), you may set the following in an initializer:
```ruby
-cell.escape_formulas = false
+Axlsx.escape_formulas = false
```
-Refer to examples/escape_formula.md for how to set `escape_formulas` on the workbook, worksheet, row and/or cell level.
-
-**Important:** The global setting `Axlsx.escape_formulas = true` will become the default in the next major release (Axlsx 4.0).
-If you do not wish to set `Axlsx.escape_formulas = true` now, at a minimum, please set `Axlsx.escape_formulas = false` to
-ensure continuity when upgrading.
-
## Known Software Interoperability Issues
As axslx implements the Office Open XML (ECMA-376 spec) much of the
diff --git a/axlsx.gemspec b/axlsx.gemspec
index bf9c0942..7951b416 100644
--- a/axlsx.gemspec
+++ b/axlsx.gemspec
@@ -16,6 +16,8 @@ Gem::Specification.new do |s|
MSG
s.files = Dir.glob("{lib/**/*,examples/**/*.rb,examples/**/*.jpeg}") + %w{LICENSE README.md Rakefile CHANGELOG.md .yardopts .yardopts_guide}
+ s.metadata = { 'rubygems_mfa_required' => 'true' }
+
s.add_runtime_dependency "htmlentities", "~> 4.3", '>= 4.3.4'
s.add_runtime_dependency "marcel", '~> 1.0'
s.add_runtime_dependency 'nokogiri', '~> 1.10', '>= 1.10.4'
diff --git a/examples/README.md b/examples/README.md
index ea76d376..b43da2bb 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -49,7 +49,7 @@ Types:
Customizations:
* [Chart colors](chart_colors_example.md)
* [Hide gridlines](hide_gridlines_in_chart_example.md)
-* [Chart series color](chart_series_example.md)
+* [Chart series color](chart_series_color_example.md)
### Columns
diff --git a/examples/basic_formula_example.md b/examples/basic_formula_example.md
index d19288fb..5a6eb878 100644
--- a/examples/basic_formula_example.md
+++ b/examples/basic_formula_example.md
@@ -7,6 +7,8 @@ You could insert formulas
```ruby
require 'axlsx'
+Axlsx.escape_formulas = false
+
p = Axlsx::Package.new
wb = p.workbook
diff --git a/examples/cached_formula_example.md b/examples/cached_formula_example.md
index e5b82264..47855b59 100644
--- a/examples/cached_formula_example.md
+++ b/examples/cached_formula_example.md
@@ -7,6 +7,8 @@ When you add a formula in Excel, it immediately calculates its value and store i
```ruby
require 'axlsx'
+Axlsx.escape_formulas = false
+
p = Axlsx::Package.new
wb = p.workbook
diff --git a/examples/column_outlines_example.md b/examples/column_outlines_example.md
index 6d402af5..5e2557e4 100644
--- a/examples/column_outlines_example.md
+++ b/examples/column_outlines_example.md
@@ -7,6 +7,8 @@ If you have a list of data that you want to group and summarize, you can create
```ruby
require 'axlsx'
+Axlsx.escape_formulas = false
+
p = Axlsx::Package.new
wb = p.workbook
diff --git a/examples/complex_example.md b/examples/complex_example.md
index 4f395b02..c0c8d7f4 100644
--- a/examples/complex_example.md
+++ b/examples/complex_example.md
@@ -7,6 +7,8 @@ This is a complex example with a worksheet full of data.
```ruby
require 'axlsx'
+Axlsx.escape_formulas = false
+
p = Axlsx::Package.new
wb = p.workbook
diff --git a/examples/defined_name_example.md b/examples/defined_name_example.md
index ce998263..b2dd3a80 100644
--- a/examples/defined_name_example.md
+++ b/examples/defined_name_example.md
@@ -7,6 +7,8 @@ You could use defined names in formulas
```ruby
require 'axlsx'
+Axlsx.escape_formulas = false
+
p = Axlsx::Package.new
wb = p.workbook
diff --git a/examples/images/sort_state_example_1.png b/examples/images/sort_state_example_1.png
new file mode 100644
index 00000000..fb13d387
--- /dev/null
+++ b/examples/images/sort_state_example_1.png
Binary files differ
diff --git a/examples/images/sort_state_example_2.png b/examples/images/sort_state_example_2.png
new file mode 100644
index 00000000..c84b6848
--- /dev/null
+++ b/examples/images/sort_state_example_2.png
Binary files differ
diff --git a/examples/row_outlines_example.md b/examples/row_outlines_example.md
index baa48cfe..78c0d55a 100644
--- a/examples/row_outlines_example.md
+++ b/examples/row_outlines_example.md
@@ -7,6 +7,8 @@ If you have a list of data that you want to group and summarize, you can create
```ruby
require 'axlsx'
+Axlsx.escape_formulas = false
+
p = Axlsx::Package.new
wb = p.workbook
diff --git a/examples/sort_state_example.md b/examples/sort_state_example.md
new file mode 100644
index 00000000..d0258c31
--- /dev/null
+++ b/examples/sort_state_example.md
@@ -0,0 +1,42 @@
+## Description
+
+You could add sort conditions to the sort state of an auto filtered table
+
+## Code
+
+```ruby
+require 'axlsx'
+
+p = Axlsx::Package.new
+wb = p.workbook
+
+wb.add_worksheet(name: 'Sort State') do |sheet|
+ sheet.add_row ['Number', 'Letter', 'Priority']
+ sheet.add_row [1, 'B', 'high']
+ sheet.add_row [2, 'B', 'low']
+ sheet.add_row [3, 'B', 'medium']
+ sheet.add_row [4, 'B', 'high']
+ sheet.add_row [5, 'B', 'low']
+ sheet.add_row [6, 'B', 'medium']
+ sheet.add_row [7, 'A', 'high']
+ sheet.add_row [8, 'A', 'low']
+ sheet.add_row [9, 'A', 'medium']
+ sheet.add_row [10, 'A', 'high']
+ sheet.add_row [11, 'A', 'low']
+ sheet.add_row [12, 'A', 'medium']
+ sheet.auto_filter = 'A1:C13'
+ sheet.auto_filter.sort_state.add_sort_condition column_index: 1
+ sheet.auto_filter.sort_state.add_sort_condition column_index: 2, custom_list: ['low', 'medium', 'high']
+ sheet.auto_filter.sort_state.add_sort_condition column_index: 0, order: :desc
+end
+
+p.serialize 'sort_state_example.xlsx'
+```
+
+## Output
+
+![Output](images/sort_state_example_1.png "Output")
+
+After adding the sort conditions:
+
+![Output](images/sort_state_example_2.png "Output")
diff --git a/lib/axlsx.rb b/lib/axlsx.rb
index aeef2dfc..1f43103e 100644
--- a/lib/axlsx.rb
+++ b/lib/axlsx.rb
@@ -30,10 +30,11 @@ require 'zip'
# core dependencies
require 'bigdecimal'
+require 'cgi'
require 'set'
require 'time'
-if Gem.loaded_specs.has_key?("axlsx_styler")
+if Gem.loaded_specs.key?("axlsx_styler")
raise StandardError, "Please remove `axlsx_styler` from your Gemfile, the associated functionality is now built-in to `caxlsx` directly."
end
@@ -219,7 +220,7 @@ module Axlsx
# See https://www.owasp.org/index.php/CSV_Injection for details.
# @return [Boolean]
def self.escape_formulas
- !defined?(@escape_formulas) || @escape_formulas.nil? ? false : @escape_formulas
+ !defined?(@escape_formulas) || @escape_formulas.nil? ? true : @escape_formulas
end
# Sets whether to treat values starting with an equals sign as formulas or as literal strings.
diff --git a/lib/axlsx/content_type/abstract_content_type.rb b/lib/axlsx/content_type/abstract_content_type.rb
index 6aae8c4b..30ab9f35 100644
--- a/lib/axlsx/content_type/abstract_content_type.rb
+++ b/lib/axlsx/content_type/abstract_content_type.rb
@@ -18,7 +18,7 @@ module Axlsx
# The content type.
# @see Axlsx#validate_content_type
- def content_type=(v) Axlsx::validate_content_type v; @content_type = v end
+ def content_type=(v) Axlsx.validate_content_type v; @content_type = v end
alias :ContentType= :content_type=
# Serialize the contenty type to xml
@@ -26,7 +26,7 @@ module Axlsx
str << '<' << node_name << ' '
Axlsx.instance_values_for(self).each_with_index do |key_value, index|
str << ' ' unless index.zero?
- str << Axlsx::camel(key_value.first) << '="' << key_value.last.to_s << '"'
+ str << Axlsx.camel(key_value.first) << '="' << key_value.last.to_s << '"'
end
str << '/>'
end
diff --git a/lib/axlsx/content_type/default.rb b/lib/axlsx/content_type/default.rb
index 16189fc6..2fbeb380 100644
--- a/lib/axlsx/content_type/default.rb
+++ b/lib/axlsx/content_type/default.rb
@@ -12,7 +12,7 @@ module Axlsx
alias :Extension :extension
# Sets the file extension for this content type.
- def extension=(v) Axlsx::validate_string v; @extension = v end
+ def extension=(v) Axlsx.validate_string v; @extension = v end
alias :Extension= :extension=
# Serializes this object to xml
diff --git a/lib/axlsx/content_type/override.rb b/lib/axlsx/content_type/override.rb
index be45db3c..99db7546 100644
--- a/lib/axlsx/content_type/override.rb
+++ b/lib/axlsx/content_type/override.rb
@@ -12,7 +12,7 @@ module Axlsx
alias :PartName :part_name
# The name and location of the part.
- def part_name=(v) Axlsx::validate_string v; @part_name = v end
+ def part_name=(v) Axlsx.validate_string v; @part_name = v end
alias :PartName= :part_name=
# Serializes this object to xml
diff --git a/lib/axlsx/doc_props/app.rb b/lib/axlsx/doc_props/app.rb
index 40a8184d..fb3f5790 100644
--- a/lib/axlsx/doc_props/app.rb
+++ b/lib/axlsx/doc_props/app.rb
@@ -132,89 +132,89 @@ module Axlsx
alias :DocSecurity :doc_security
# Sets the template property of your app.xml file
- def template=(v) Axlsx::validate_string v; @template = v; end
+ def template=(v) Axlsx.validate_string v; @template = v; end
alias :Template= :template=
# Sets the manager property of your app.xml file
- def manager=(v) Axlsx::validate_string v; @manager = v; end
+ def manager=(v) Axlsx.validate_string v; @manager = v; end
alias :Manager= :manager=
# Sets the company property of your app.xml file
- def company=(v) Axlsx::validate_string v; @company = v; end
+ def company=(v) Axlsx.validate_string v; @company = v; end
alias :Company= :company=
# Sets the pages property of your app.xml file
- def pages=(v) Axlsx::validate_int v; @pages = v; end
+ def pages=(v) Axlsx.validate_int v; @pages = v; end
# Sets the words property of your app.xml file
- def words=(v) Axlsx::validate_int v; @words = v; end
+ def words=(v) Axlsx.validate_int v; @words = v; end
alias :Words= :words=
# Sets the characters property of your app.xml file
- def characters=(v) Axlsx::validate_int v; @characters = v; end
+ def characters=(v) Axlsx.validate_int v; @characters = v; end
alias :Characters= :characters=
# Sets the presentation_format property of your app.xml file
- def presentation_format=(v) Axlsx::validate_string v; @presentation_format = v; end
+ def presentation_format=(v) Axlsx.validate_string v; @presentation_format = v; end
alias :PresentationFormat= :presentation_format=
# Sets the lines property of your app.xml file
- def lines=(v) Axlsx::validate_int v; @lines = v; end
+ def lines=(v) Axlsx.validate_int v; @lines = v; end
alias :Lines= :lines=
# Sets the paragraphs property of your app.xml file
- def paragraphs=(v) Axlsx::validate_int v; @paragraphs = v; end
+ def paragraphs=(v) Axlsx.validate_int v; @paragraphs = v; end
alias :Paragraphs= :paragraphs=
# sets the slides property of your app.xml file
- def slides=(v) Axlsx::validate_int v; @slides = v; end
+ def slides=(v) Axlsx.validate_int v; @slides = v; end
alias :Slides= :slides=
# sets the notes property of your app.xml file
- def notes=(v) Axlsx::validate_int v; @notes = v; end
+ def notes=(v) Axlsx.validate_int v; @notes = v; end
alias :Notes= :notes=
# Sets the total_time property of your app.xml file
- def total_time=(v) Axlsx::validate_int v; @total_time = v; end
+ def total_time=(v) Axlsx.validate_int v; @total_time = v; end
alias :TotalTime= :total_time=
# Sets the hidden_slides property of your app.xml file
- def hidden_slides=(v) Axlsx::validate_int v; @hidden_slides = v; end
+ def hidden_slides=(v) Axlsx.validate_int v; @hidden_slides = v; end
alias :HiddenSlides= :hidden_slides=
# Sets the m_m_clips property of your app.xml file
- def m_m_clips=(v) Axlsx::validate_int v; @m_m_clips = v; end
+ def m_m_clips=(v) Axlsx.validate_int v; @m_m_clips = v; end
alias :MMClips= :m_m_clips=
# Sets the scale_crop property of your app.xml file
- def scale_crop=(v) Axlsx::validate_boolean v; @scale_crop = v; end
+ def scale_crop=(v) Axlsx.validate_boolean v; @scale_crop = v; end
alias :ScaleCrop= :scale_crop=
# Sets the links_up_to_date property of your app.xml file
- def links_up_to_date=(v) Axlsx::validate_boolean v; @links_up_to_date = v; end
+ def links_up_to_date=(v) Axlsx.validate_boolean v; @links_up_to_date = v; end
alias :LinksUpToDate= :links_up_to_date=
# Sets the characters_with_spaces property of your app.xml file
- def characters_with_spaces=(v) Axlsx::validate_int v; @characters_with_spaces = v; end
+ def characters_with_spaces=(v) Axlsx.validate_int v; @characters_with_spaces = v; end
alias :CharactersWithSpaces= :characters_with_spaces=
# Sets the share_doc property of your app.xml file
- def shared_doc=(v) Axlsx::validate_boolean v; @shared_doc = v; end
+ def shared_doc=(v) Axlsx.validate_boolean v; @shared_doc = v; end
alias :SharedDoc= :shared_doc=
# Sets the hyperlink_base property of your app.xml file
- def hyperlink_base=(v) Axlsx::validate_string v; @hyperlink_base = v; end
+ def hyperlink_base=(v) Axlsx.validate_string v; @hyperlink_base = v; end
alias :HyperlinkBase= :hyperlink_base=
# Sets the HyperLinksChanged property of your app.xml file
- def hyperlinks_changed=(v) Axlsx::validate_boolean v; @hyperlinks_changed = v; end
+ def hyperlinks_changed=(v) Axlsx.validate_boolean v; @hyperlinks_changed = v; end
alias :HyperLinksChanged= :hyperlinks_changed=
# Sets the app_version property of your app.xml file
- def app_version=(v) Axlsx::validate_string v; @app_version = v; end
+ def app_version=(v) Axlsx.validate_string v; @app_version = v; end
alias :AppVersion= :app_version=
# Sets the doc_security property of your app.xml file
- def doc_security=(v) Axlsx::validate_int v; @doc_security = v; end
+ def doc_security=(v) Axlsx.validate_int v; @doc_security = v; end
alias :DocSecurity= :doc_security=
# Serialize the app.xml document
diff --git a/lib/axlsx/doc_props/core.rb b/lib/axlsx/doc_props/core.rb
index 8dbe4cf4..4e98ac8e 100644
--- a/lib/axlsx/doc_props/core.rb
+++ b/lib/axlsx/doc_props/core.rb
@@ -27,7 +27,7 @@ module Axlsx
str << '<cp:coreProperties xmlns:cp="' << CORE_NS << '" xmlns:dc="' << CORE_NS_DC << '" '
str << 'xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" '
str << 'xmlns:xsi="' << CORE_NS_XSI << '">'
- str << '<dc:creator>' << self.creator << '</dc:creator>'
+ str << '<dc:creator>' << creator << '</dc:creator>'
str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << (created || Time.now).strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>'
str << '<cp:revision>0</cp:revision>'
str << '</cp:coreProperties>'
diff --git a/lib/axlsx/drawing/area_chart.rb b/lib/axlsx/drawing/area_chart.rb
index 8a01f9f5..1d26a8fc 100644
--- a/lib/axlsx/drawing/area_chart.rb
+++ b/lib/axlsx/drawing/area_chart.rb
@@ -63,7 +63,7 @@ module Axlsx
# chart based on the actual class type and not a fixed node name.
# @return [String]
def node_name
- path = self.class.to_s
+ path = self.class.name
if i = path.rindex('::')
path = path[(i + 2)..-1]
end
diff --git a/lib/axlsx/drawing/area_series.rb b/lib/axlsx/drawing/area_series.rb
index c43fe929..0e3d8928 100644
--- a/lib/axlsx/drawing/area_series.rb
+++ b/lib/axlsx/drawing/area_series.rb
@@ -52,19 +52,19 @@ module Axlsx
# @see show_marker
def show_marker=(v)
- Axlsx::validate_boolean(v)
+ Axlsx.validate_boolean(v)
@show_marker = v
end
# @see marker_symbol
def marker_symbol=(v)
- Axlsx::validate_marker_symbol(v)
+ Axlsx.validate_marker_symbol(v)
@marker_symbol = v
end
# @see smooth
def smooth=(v)
- Axlsx::validate_boolean(v)
+ Axlsx.validate_boolean(v)
@smooth = v
end
@@ -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/axis.rb b/lib/axlsx/drawing/axis.rb
index dfef7890..ed3df5f1 100644
--- a/lib/axlsx/drawing/axis.rb
+++ b/lib/axlsx/drawing/axis.rb
@@ -109,15 +109,15 @@ module Axlsx
# The number format format code for this axis
# default :General
- def format_code=(v) Axlsx::validate_string(v); @format_code = v; end
+ def format_code=(v) Axlsx.validate_string(v); @format_code = v; end
# Specify if gridlines should be shown for this axis
# default true
- def gridlines=(v) Axlsx::validate_boolean(v); @gridlines = v; end
+ def gridlines=(v) Axlsx.validate_boolean(v); @gridlines = v; end
# Specify if axis should be removed from the chart
# default false
- def delete=(v) Axlsx::validate_boolean(v); @delete = v; end
+ def delete=(v) Axlsx.validate_boolean(v); @delete = v; end
# specifies how the perpendicular axis is crossed
# must be one of [:autoZero, :min, :max]
@@ -126,9 +126,9 @@ module Axlsx
# Specify the degree of label rotation to apply to labels
# default true
def label_rotation=(v)
- Axlsx::validate_int(v)
+ Axlsx.validate_int(v)
adjusted = v.to_i * 60000
- Axlsx::validate_angle(adjusted)
+ Axlsx.validate_angle(adjusted)
@label_rotation = adjusted
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/cat_axis.rb b/lib/axlsx/drawing/cat_axis.rb
index d26e3dc9..d078eb6f 100644
--- a/lib/axlsx/drawing/cat_axis.rb
+++ b/lib/axlsx/drawing/cat_axis.rb
@@ -45,15 +45,15 @@ module Axlsx
LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)/.freeze
# @see tick_lbl_skip
- def tick_lbl_skip=(v) Axlsx::validate_unsigned_int(v); @tick_lbl_skip = v; end
+ def tick_lbl_skip=(v) Axlsx.validate_unsigned_int(v); @tick_lbl_skip = v; end
alias :tickLblSkip= :tick_lbl_skip=
# @see tick_mark_skip
- def tick_mark_skip=(v) Axlsx::validate_unsigned_int(v); @tick_mark_skip = v; end
+ def tick_mark_skip=(v) Axlsx.validate_unsigned_int(v); @tick_mark_skip = v; end
alias :tickMarkSkip= :tick_mark_skip=
# From the docs: This element specifies that this axis is a date or text axis based on the data that is used for the axis labels, not a specific choice.
- def auto=(v) Axlsx::validate_boolean(v); @auto = v; end
+ def auto=(v) Axlsx.validate_boolean(v); @auto = v; end
# specifies how the perpendicular axis is crossed
# must be one of [:ctr, :l, :r]
diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb
index 9f59dc6a..c84e5cba 100644
--- a/lib/axlsx/drawing/chart.rb
+++ b/lib/axlsx/drawing/chart.rb
@@ -62,7 +62,7 @@ module Axlsx
# Configures the vary_colors options for this chart
# @param [Boolean] v The value to set
- def vary_colors=(v) Axlsx::validate_boolean(v); @vary_colors = v; end
+ def vary_colors=(v) Axlsx.validate_boolean(v); @vary_colors = v; end
# The title object for the chart.
# @return [Title]
@@ -124,7 +124,7 @@ module Axlsx
# The part name for this chart
# @return [String]
def pn
- "#{CHART_PN % (index + 1)}"
+ format(CHART_PN, index + 1)
end
# The title object for the chart.
@@ -149,18 +149,18 @@ module Axlsx
# Show the legend in the chart
# @param [Boolean] v
# @return [Boolean]
- def show_legend=(v) Axlsx::validate_boolean(v); @show_legend = v; end
+ def show_legend=(v) Axlsx.validate_boolean(v); @show_legend = v; end
# How to display blank values
# @see display_blanks_as
# @param [Symbol] v
# @return [Symbol]
- def display_blanks_as=(v) Axlsx::validate_display_blanks_as(v); @display_blanks_as = v; end
+ def display_blanks_as=(v) Axlsx.validate_display_blanks_as(v); @display_blanks_as = v; end
# The style for the chart.
# see ECMA Part 1 §21.2.2.196
# @param [Integer] v must be between 1 and 48
- def style=(v) DataTypeValidator.validate "Chart.style", Integer, v, lambda { |arg| arg >= 1 && arg <= 48 }; @style = v; end
+ def style=(v) DataTypeValidator.validate "Chart.style", Integer, v, ->(arg) { arg >= 1 && arg <= 48 }; @style = v; end
# @see legend_position
def legend_position=(v) RestrictionValidator.validate "Chart.legend_position", [:b, :l, :r, :t, :tr], v; @legend_position = v; end
@@ -194,12 +194,12 @@ module Axlsx
# Whether only data from visible cells should be plotted.
# @param [Boolean] v
# @return [Boolean]
- def plot_visible_only=(v) Axlsx::validate_boolean(v); @plot_visible_only = v; end
+ def plot_visible_only=(v) Axlsx.validate_boolean(v); @plot_visible_only = v; end
# Whether the chart area shall have rounded corners.
# @param [Boolean] v
# @return [Boolean]
- def rounded_corners=(v) Axlsx::validate_boolean(v); @rounded_corners = v; end
+ def rounded_corners=(v) Axlsx.validate_boolean(v); @rounded_corners = v; end
# Serializes the object
# @param [String] str
diff --git a/lib/axlsx/drawing/d_lbls.rb b/lib/axlsx/drawing/d_lbls.rb
index 7e3936cc..0602a8df 100644
--- a/lib/axlsx/drawing/d_lbls.rb
+++ b/lib/axlsx/drawing/d_lbls.rb
@@ -38,7 +38,7 @@ module Axlsx
[:show_legend_key, :show_val, :show_cat_name,
:show_ser_name, :show_percent, :show_bubble_size,
:show_leader_lines].each do |attr|
- self.send("#{attr}=", false)
+ send("#{attr}=", false)
end
end
@@ -78,7 +78,7 @@ module Axlsx
%w(d_lbl_pos show_legend_key show_val show_cat_name show_ser_name show_percent show_bubble_size show_leader_lines).each do |key|
next unless instance_vals.key?(key) && !instance_vals[key].nil?
- str << "<c:#{Axlsx::camel(key, false)} val='#{instance_vals[key]}' />"
+ str << "<c:#{Axlsx.camel(key, false)} val='#{instance_vals[key]}' />"
end
str << '</c:dLbls>'
end
diff --git a/lib/axlsx/drawing/drawing.rb b/lib/axlsx/drawing/drawing.rb
index fa7a608c..997a7af0 100644
--- a/lib/axlsx/drawing/drawing.rb
+++ b/lib/axlsx/drawing/drawing.rb
@@ -108,7 +108,7 @@ module Axlsx
# An array of hyperlink objects associated with this drawings images
# @return [Array]
def hyperlinks
- links = self.images.select { |a| a.hyperlink.is_a?(Hyperlink) }
+ links = images.select { |a| a.hyperlink.is_a?(Hyperlink) }
links.map(&:hyperlink)
end
@@ -128,14 +128,14 @@ module Axlsx
# The part name for this drawing
# @return [String]
def pn
- "#{DRAWING_PN % (index + 1)}"
+ format(DRAWING_PN, index + 1)
end
# The relational part name for this drawing
# #NOTE This should be rewritten to return an Axlsx::Relationship object.
# @return [String]
def rels_pn
- "#{DRAWING_RELS_PN % (index + 1)}"
+ format(DRAWING_RELS_PN, index + 1)
end
# A list of objects this drawing holds.
diff --git a/lib/axlsx/drawing/hyperlink.rb b/lib/axlsx/drawing/hyperlink.rb
index acf3b8d2..682aae29 100644
--- a/lib/axlsx/drawing/hyperlink.rb
+++ b/lib/axlsx/drawing/hyperlink.rb
@@ -52,7 +52,7 @@ module Axlsx
# @see endSnd
# @param [Boolean] v The boolean value indicating the termination of playing sounds on click
# @return [Boolean]
- def end_snd=(v) Axlsx::validate_boolean(v); @end_snd = v end
+ def end_snd=(v) Axlsx.validate_boolean(v); @end_snd = v end
alias :endSnd= :end_snd=
# indicates that the link has already been clicked.
@@ -62,7 +62,7 @@ module Axlsx
# @see highlightClick
# @param [Boolean] v The value to assign
- def highlight_click=(v) Axlsx::validate_boolean(v); @highlight_click = v end
+ def highlight_click=(v) Axlsx.validate_boolean(v); @highlight_click = v end
alias :highlightClick= :highlight_click=
# From the specs: Specifies whether to add this URI to the history when navigating to it. This allows for the viewing of this presentation without the storing of history information on the viewing machine. If this attribute is omitted, then a value of 1 or true is assumed.
@@ -71,7 +71,7 @@ module Axlsx
# @see history
# param [Boolean] v The value to assing
- def history=(v) Axlsx::validate_boolean(v); @history = v end
+ def history=(v) Axlsx.validate_boolean(v); @history = v end
# From the specs: Specifies the target frame that is to be used when opening this hyperlink. When the hyperlink is activated this attribute is used to determine if a new window is launched for viewing or if an existing one can be used. If this attribute is omitted, than a new window is opened.
# @return [String]
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_chart.rb b/lib/axlsx/drawing/line_chart.rb
index 14577900..c922de78 100644
--- a/lib/axlsx/drawing/line_chart.rb
+++ b/lib/axlsx/drawing/line_chart.rb
@@ -63,7 +63,7 @@ module Axlsx
# chart based on the actual class type and not a fixed node name.
# @return [String]
def node_name
- path = self.class.to_s
+ path = self.class.name
if i = path.rindex('::')
path = path[(i + 2)..-1]
end
diff --git a/lib/axlsx/drawing/line_series.rb b/lib/axlsx/drawing/line_series.rb
index d6a412e4..13492419 100644
--- a/lib/axlsx/drawing/line_series.rb
+++ b/lib/axlsx/drawing/line_series.rb
@@ -52,19 +52,19 @@ module Axlsx
# @see show_marker
def show_marker=(v)
- Axlsx::validate_boolean(v)
+ Axlsx.validate_boolean(v)
@show_marker = v
end
# @see marker_symbol
def marker_symbol=(v)
- Axlsx::validate_marker_symbol(v)
+ Axlsx.validate_marker_symbol(v)
@marker_symbol = v
end
# @see smooth
def smooth=(v)
- Axlsx::validate_boolean(v)
+ Axlsx.validate_boolean(v)
@smooth = v
end
@@ -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/marker.rb b/lib/axlsx/drawing/marker.rb
index a1801eb9..0d6e0077 100644
--- a/lib/axlsx/drawing/marker.rb
+++ b/lib/axlsx/drawing/marker.rb
@@ -34,13 +34,13 @@ module Axlsx
attr_reader :rowOff
# @see col
- def col=(v) Axlsx::validate_unsigned_int v; @col = v end
+ def col=(v) Axlsx.validate_unsigned_int v; @col = v end
# @see colOff
- def colOff=(v) Axlsx::validate_int v; @colOff = v end
+ def colOff=(v) Axlsx.validate_int v; @colOff = v end
# @see row
- def row=(v) Axlsx::validate_unsigned_int v; @row = v end
+ def row=(v) Axlsx.validate_unsigned_int v; @row = v end
# @see rowOff
- def rowOff=(v) Axlsx::validate_int v; @rowOff = v end
+ def rowOff=(v) Axlsx.validate_int v; @rowOff = v end
# shortcut to set the column, row position for this marker
# @param col the column for the marker, a Cell object or a string reference like "B7"
@@ -58,7 +58,7 @@ module Axlsx
# @return [String]
def to_xml_string(str = +'')
[:col, :colOff, :row, :rowOff].each do |k|
- str << '<xdr:' << k.to_s << '>' << self.send(k).to_s << '</xdr:' << k.to_s << '>'
+ str << '<xdr:' << k.to_s << '>' << send(k).to_s << '</xdr:' << k.to_s << '>'
end
end
@@ -68,7 +68,7 @@ module Axlsx
# @see Chart#start_at
def parse_coord_args(x, y = 0)
if x.is_a?(String)
- x, y = *Axlsx::name_to_indices(x)
+ x, y = *Axlsx.name_to_indices(x)
end
if x.is_a?(Cell)
x, y = *x.pos
diff --git a/lib/axlsx/drawing/num_data.rb b/lib/axlsx/drawing/num_data.rb
index 356926b2..3ad23cb4 100644
--- a/lib/axlsx/drawing/num_data.rb
+++ b/lib/axlsx/drawing/num_data.rb
@@ -31,7 +31,7 @@ module Axlsx
# @see format_code
def format_code=(v = 'General')
- Axlsx::validate_string(v)
+ Axlsx.validate_string(v)
@format_code = v
end
diff --git a/lib/axlsx/drawing/num_data_source.rb b/lib/axlsx/drawing/num_data_source.rb
index 0845ad31..b4081aae 100644
--- a/lib/axlsx/drawing/num_data_source.rb
+++ b/lib/axlsx/drawing/num_data_source.rb
@@ -17,7 +17,7 @@ module Axlsx
@f = nil
@data = @data_type.new(options)
if options[:data] && options[:data].first.is_a?(Cell)
- @f = Axlsx::cell_range(options[:data])
+ @f = Axlsx.cell_range(options[:data])
end
parse_options options
end
diff --git a/lib/axlsx/drawing/num_val.rb b/lib/axlsx/drawing/num_val.rb
index 19829a30..a945fb65 100644
--- a/lib/axlsx/drawing/num_val.rb
+++ b/lib/axlsx/drawing/num_val.rb
@@ -18,14 +18,14 @@ module Axlsx
# @see format_code
def format_code=(v)
- Axlsx::validate_string(v)
+ Axlsx.validate_string(v)
@format_code = v
end
# serialize the object
def to_xml_string(idx, str = +'')
- Axlsx::validate_unsigned_int(idx)
- if !v.to_s.empty?
+ Axlsx.validate_unsigned_int(idx)
+ 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/one_cell_anchor.rb b/lib/axlsx/drawing/one_cell_anchor.rb
index 402b51ab..22b09944 100644
--- a/lib/axlsx/drawing/one_cell_anchor.rb
+++ b/lib/axlsx/drawing/one_cell_anchor.rb
@@ -60,10 +60,10 @@ module Axlsx
#
# @see height
- def height=(v) Axlsx::validate_unsigned_int(v); @height = v; end
+ def height=(v) Axlsx.validate_unsigned_int(v); @height = v; end
# @see width
- def width=(v) Axlsx::validate_unsigned_int(v); @width = v; end
+ def width=(v) Axlsx.validate_unsigned_int(v); @width = v; end
# The index of this anchor in the drawing
# @return [Integer]
diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb
index 150d6dc5..630d8d96 100644
--- a/lib/axlsx/drawing/pic.rb
+++ b/lib/axlsx/drawing/pic.rb
@@ -78,7 +78,7 @@ module Axlsx
end
def image_src=(v)
- Axlsx::validate_string(v)
+ Axlsx.validate_string(v)
if remote?
RegexValidator.validate('Pic.image_src', /\A#{URI::DEFAULT_PARSER.make_regexp}\z/, v)
RestrictionValidator.validate 'Pic.image_src', ALLOWED_MIME_TYPES, MimeTypeUtils.get_mime_type_from_uri(v)
@@ -91,13 +91,13 @@ module Axlsx
end
# @see name
- def name=(v) Axlsx::validate_string(v); @name = v; end
+ def name=(v) Axlsx.validate_string(v); @name = v; end
# @see descr
- def descr=(v) Axlsx::validate_string(v); @descr = v; end
+ def descr=(v) Axlsx.validate_string(v); @descr = v; end
# @see remote
- def remote=(v) Axlsx::validate_boolean(v); @remote = v; end
+ def remote=(v) Axlsx.validate_boolean(v); @remote = v; end
def remote?
remote == 1 || remote.to_s == 'true'
@@ -124,14 +124,14 @@ module Axlsx
# The part name for this image used in serialization and relationship building
# @return [String]
def pn
- "#{IMAGE_PN % [(index + 1), extname]}"
+ format(IMAGE_PN, index + 1, extname)
end
# The relationship object for this pic.
# @return [Relationship]
def relationship
if remote?
- Relationship.new(self, IMAGE_R, "#{image_src}", target_mode: :External)
+ Relationship.new(self, IMAGE_R, image_src.to_s, target_mode: :External)
else
Relationship.new(self, IMAGE_R, "../#{pn}")
end
diff --git a/lib/axlsx/drawing/pie_series.rb b/lib/axlsx/drawing/pie_series.rb
index 091267f4..416cd93c 100644
--- a/lib/axlsx/drawing/pie_series.rb
+++ b/lib/axlsx/drawing/pie_series.rb
@@ -39,7 +39,7 @@ module Axlsx
def colors=(v) DataTypeValidator.validate "BarSeries.colors", [Array], v; @colors = v end
# @see explosion
- def explosion=(v) Axlsx::validate_unsigned_int(v); @explosion = v; end
+ def explosion=(v) Axlsx.validate_unsigned_int(v); @explosion = v; end
# Serializes the object
# @param [String] str
diff --git a/lib/axlsx/drawing/scaling.rb b/lib/axlsx/drawing/scaling.rb
index 4d5a9d2a..c9101ead 100644
--- a/lib/axlsx/drawing/scaling.rb
+++ b/lib/axlsx/drawing/scaling.rb
@@ -35,7 +35,7 @@ module Axlsx
attr_reader :min
# @see logBase
- def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer], v, lambda { |arg| arg >= 2 && arg <= 1000 }; @logBase = v; end
+ def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer], v, ->(arg) { arg >= 2 && arg <= 1000 }; @logBase = v; end
# @see orientation
def orientation=(v) RestrictionValidator.validate "Scaling.orientation", [:minMax, :maxMin], v; @orientation = v; end
# @see max
diff --git a/lib/axlsx/drawing/scatter_series.rb b/lib/axlsx/drawing/scatter_series.rb
index 2838c3de..865c6f85 100644
--- a/lib/axlsx/drawing/scatter_series.rb
+++ b/lib/axlsx/drawing/scatter_series.rb
@@ -43,7 +43,7 @@ module Axlsx
@smooth = [:smooth, :smoothMarker].include?(chart.scatter_style)
else
# Set smoothing according to the option provided
- Axlsx::validate_boolean(options[:smooth])
+ Axlsx.validate_boolean(options[:smooth])
@smooth = options[:smooth]
end
@ln_width = options[:ln_width] unless options[:ln_width].nil?
@@ -62,7 +62,7 @@ module Axlsx
# @see smooth
def smooth=(v)
- Axlsx::validate_boolean(v)
+ Axlsx.validate_boolean(v)
@smooth = v
end
@@ -73,7 +73,7 @@ module Axlsx
# @see marker_symbol
def marker_symbol=(v)
- Axlsx::validate_marker_symbol(v)
+ Axlsx.validate_marker_symbol(v)
@marker_symbol = v
end
@@ -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/ser_axis.rb b/lib/axlsx/drawing/ser_axis.rb
index 4fea58e5..24eb0926 100644
--- a/lib/axlsx/drawing/ser_axis.rb
+++ b/lib/axlsx/drawing/ser_axis.rb
@@ -22,11 +22,11 @@ module Axlsx
end
# @see tickLblSkip
- def tick_lbl_skip=(v) Axlsx::validate_unsigned_int(v); @tick_lbl_skip = v; end
+ def tick_lbl_skip=(v) Axlsx.validate_unsigned_int(v); @tick_lbl_skip = v; end
alias :tickLblSkip= :tick_lbl_skip=
# @see tickMarkSkip
- def tick_mark_skip=(v) Axlsx::validate_unsigned_int(v); @tick_mark_skip = v; end
+ def tick_mark_skip=(v) Axlsx.validate_unsigned_int(v); @tick_mark_skip = v; end
alias :tickMarkSkip= :tick_mark_skip=
# Serializes the object
diff --git a/lib/axlsx/drawing/series.rb b/lib/axlsx/drawing/series.rb
index 5a91dd44..134cd7d0 100644
--- a/lib/axlsx/drawing/series.rb
+++ b/lib/axlsx/drawing/series.rb
@@ -40,7 +40,7 @@ module Axlsx
end
# @see order
- def order=(v) Axlsx::validate_unsigned_int(v); @order = v; end
+ def order=(v) Axlsx.validate_unsigned_int(v); @order = v; end
# @see title
def title=(v)
diff --git a/lib/axlsx/drawing/series_title.rb b/lib/axlsx/drawing/series_title.rb
index 08e5e909..366fc175 100644
--- a/lib/axlsx/drawing/series_title.rb
+++ b/lib/axlsx/drawing/series_title.rb
@@ -7,11 +7,11 @@ module Axlsx
# @param [String] str
# @return [String]
def to_xml_string(str = +'')
- clean_value = Axlsx::trust_input ? @text.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@text.to_s))
+ clean_value = Axlsx.trust_input ? @text.to_s : ::CGI.escapeHTML(Axlsx.sanitize(@text.to_s))
str << '<c:tx>'
str << '<c:strRef>'
- str << '<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>'
+ str << '<c:f>' << Axlsx.cell_range([@cell]) << '</c:f>'
str << '<c:strCache>'
str << '<c:ptCount val="1"/>'
str << '<c:pt idx="0">'
diff --git a/lib/axlsx/drawing/str_val.rb b/lib/axlsx/drawing/str_val.rb
index d09e6ce8..8bae630d 100644
--- a/lib/axlsx/drawing/str_val.rb
+++ b/lib/axlsx/drawing/str_val.rb
@@ -24,8 +24,8 @@ module Axlsx
# serialize the object
def to_xml_string(idx, str = +'')
- Axlsx::validate_unsigned_int(idx)
- if !v.to_s.empty?
+ Axlsx.validate_unsigned_int(idx)
+ 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/drawing/title.rb b/lib/axlsx/drawing/title.rb
index 84687a32..8fa79e52 100644
--- a/lib/axlsx/drawing/title.rb
+++ b/lib/axlsx/drawing/title.rb
@@ -69,11 +69,11 @@ module Axlsx
def to_xml_string(str = +'')
str << '<c:title>'
unless empty?
- clean_value = Axlsx::trust_input ? @text.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@text.to_s))
+ clean_value = Axlsx.trust_input ? @text.to_s : ::CGI.escapeHTML(Axlsx.sanitize(@text.to_s))
str << '<c:tx>'
if @cell.is_a?(Cell)
str << '<c:strRef>'
- str << '<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>'
+ str << '<c:f>' << Axlsx.cell_range([@cell]) << '</c:f>'
str << '<c:strCache>'
str << '<c:ptCount val="1"/>'
str << '<c:pt idx="0">'
diff --git a/lib/axlsx/drawing/view_3D.rb b/lib/axlsx/drawing/view_3D.rb
index 9b3489a3..c3f5838d 100644
--- a/lib/axlsx/drawing/view_3D.rb
+++ b/lib/axlsx/drawing/view_3D.rb
@@ -82,7 +82,7 @@ module Axlsx
alias :depthPercent= :depth_percent=
# @see r_ang_ax
- def r_ang_ax=(v) Axlsx::validate_boolean(v); @r_ang_ax = v; end
+ def r_ang_ax=(v) Axlsx.validate_boolean(v); @r_ang_ax = v; end
alias :rAngAx= :r_ang_ax=
# @see perspective
@@ -111,7 +111,7 @@ module Axlsx
val = Axlsx.instance_values_for(self)[name]
return "" if val.nil?
- "<%s:%s val='%s'/>" % [namespace, Axlsx::camel(name, false), val]
+ format("<%s:%s val='%s'/>", namespace, Axlsx.camel(name, false), val)
end
end
end
diff --git a/lib/axlsx/drawing/vml_drawing.rb b/lib/axlsx/drawing/vml_drawing.rb
index 364ce19a..9132b00c 100644
--- a/lib/axlsx/drawing/vml_drawing.rb
+++ b/lib/axlsx/drawing/vml_drawing.rb
@@ -14,7 +14,7 @@ module Axlsx
# The part name for this vml drawing
# @return [String]
def pn
- "#{VML_DRAWING_PN}" % (@comments.worksheet.index + 1)
+ format(VML_DRAWING_PN, @comments.worksheet.index + 1)
end
# serialize the vml_drawing to xml.
diff --git a/lib/axlsx/drawing/vml_shape.rb b/lib/axlsx/drawing/vml_shape.rb
index f1cd8951..4b21528f 100644
--- a/lib/axlsx/drawing/vml_shape.rb
+++ b/lib/axlsx/drawing/vml_shape.rb
@@ -24,7 +24,7 @@ module Axlsx
@right_offset = 50
@bottom_offset = 5
@visible = true
- @id = (0...8).map { 65.+(rand(25)).chr }.join
+ @id = Array.new(8) { rand(65..89).chr }.join
parse_options options
yield self if block_given?
end
diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb
index 26f838f8..34add29b 100644
--- a/lib/axlsx/package.rb
+++ b/lib/axlsx/package.rb
@@ -33,7 +33,7 @@ module Axlsx
# Shortcut to specify that the workbook should use autowidth
# @see Workbook#use_autowidth
def use_autowidth=(v)
- Axlsx::validate_boolean(v)
+ Axlsx.validate_boolean(v)
workbook.use_autowidth = v
end
@@ -46,7 +46,7 @@ module Axlsx
# Shortcut to specify that the workbook should use shared strings
# @see Workbook#use_shared_strings
def use_shared_strings=(v)
- Axlsx::validate_boolean(v)
+ Axlsx.validate_boolean(v)
workbook.use_shared_strings = v
end
@@ -101,12 +101,12 @@ 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
confirm_valid, zip_command = parse_serialize_options(options, secondary_options)
- return false unless !confirm_valid || self.validate.empty?
+ return false unless !confirm_valid || validate.empty?
zip_provider = if zip_command
ZipCommand.new(zip_command)
@@ -126,11 +126,11 @@ 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
- return false unless !confirm_valid || self.validate.empty?
+ return false unless !confirm_valid || validate.empty?
Relationship.initialize_ids_cache
stream = BufferedZipOutputStream.write_buffer do |zip|
@@ -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/rels/relationship.rb b/lib/axlsx/rels/relationship.rb
index 93cdc88b..62860f50 100644
--- a/lib/axlsx/rels/relationship.rb
+++ b/lib/axlsx/rels/relationship.rb
@@ -92,9 +92,9 @@ module Axlsx
end
# @see Target
- def Target=(v) Axlsx::validate_string v; @Target = v end
+ def Target=(v) Axlsx.validate_string v; @Target = v end
# @see Type
- def Type=(v) Axlsx::validate_relationship_type v; @Type = v end
+ def Type=(v) Axlsx.validate_relationship_type v; @Type = v end
# @see TargetMode
def TargetMode=(v) RestrictionValidator.validate 'Relationship.TargetMode', [:External, :Internal], v; @TargetMode = v; end
@@ -107,7 +107,7 @@ module Axlsx
str << '<Relationship '
h.each_with_index do |key_value, index|
str << ' ' unless index.zero?
- str << key_value.first.to_s << '="' << Axlsx::coder.encode(key_value.last.to_s) << '"'
+ str << key_value.first.to_s << '="' << Axlsx.coder.encode(key_value.last.to_s) << '"'
end
str << '/>'
end
diff --git a/lib/axlsx/stylesheet/border.rb b/lib/axlsx/stylesheet/border.rb
index 163479b1..41f8c64d 100644
--- a/lib/axlsx/stylesheet/border.rb
+++ b/lib/axlsx/stylesheet/border.rb
@@ -43,15 +43,15 @@ module Axlsx
attr_reader :prs
# @see diagonalUp
- def diagonal_up=(v) Axlsx::validate_boolean v; @diagonal_up = v end
+ def diagonal_up=(v) Axlsx.validate_boolean v; @diagonal_up = v end
alias :diagonalUp= :diagonal_up=
# @see diagonalDown
- def diagonal_down=(v) Axlsx::validate_boolean v; @diagonal_down = v end
+ def diagonal_down=(v) Axlsx.validate_boolean v; @diagonal_down = v end
alias :diagonalDown= :diagonal_down=
# @see outline
- def outline=(v) Axlsx::validate_boolean v; @outline = v end
+ def outline=(v) Axlsx.validate_boolean v; @outline = v end
# Serializes the object
# @param [String] str
diff --git a/lib/axlsx/stylesheet/cell_alignment.rb b/lib/axlsx/stylesheet/cell_alignment.rb
index 4a0c0686..964eec33 100644
--- a/lib/axlsx/stylesheet/cell_alignment.rb
+++ b/lib/axlsx/stylesheet/cell_alignment.rb
@@ -86,34 +86,34 @@ module Axlsx
alias :readingOrder :reading_order
# @see horizontal
- def horizontal=(v) Axlsx::validate_horizontal_alignment v; @horizontal = v end
+ def horizontal=(v) Axlsx.validate_horizontal_alignment v; @horizontal = v end
# @see vertical
- def vertical=(v) Axlsx::validate_vertical_alignment v; @vertical = v end
+ def vertical=(v) Axlsx.validate_vertical_alignment v; @vertical = v end
# @see textRotation
- def text_rotation=(v) Axlsx::validate_unsigned_int v; @text_rotation = v end
+ def text_rotation=(v) Axlsx.validate_unsigned_int v; @text_rotation = v end
alias :textRotation= :text_rotation=
# @see wrapText
- def wrap_text=(v) Axlsx::validate_boolean v; @wrap_text = v end
+ def wrap_text=(v) Axlsx.validate_boolean v; @wrap_text = v end
alias :wrapText= :wrap_text=
# @see indent
- def indent=(v) Axlsx::validate_unsigned_int v; @indent = v end
+ def indent=(v) Axlsx.validate_unsigned_int v; @indent = v end
# @see relativeIndent
- def relative_indent=(v) Axlsx::validate_int v; @relative_indent = v end
+ def relative_indent=(v) Axlsx.validate_int v; @relative_indent = v end
alias :relativeIndent= :relative_indent=
# @see justifyLastLine
- def justify_last_line=(v) Axlsx::validate_boolean v; @justify_last_line = v end
+ def justify_last_line=(v) Axlsx.validate_boolean v; @justify_last_line = v end
alias :justifyLastLine= :justify_last_line=
# @see shrinkToFit
- def shrink_to_fit=(v) Axlsx::validate_boolean v; @shrink_to_fit = v end
+ def shrink_to_fit=(v) Axlsx.validate_boolean v; @shrink_to_fit = v end
alias :shrinkToFit= :shrink_to_fit=
# @see readingOrder
- def reading_order=(v) Axlsx::validate_unsigned_int v; @reading_order = v end
+ def reading_order=(v) Axlsx.validate_unsigned_int v; @reading_order = v end
alias :readingOrder= :reading_order=
# Serializes the object
diff --git a/lib/axlsx/stylesheet/cell_protection.rb b/lib/axlsx/stylesheet/cell_protection.rb
index caa01ced..f2915f25 100644
--- a/lib/axlsx/stylesheet/cell_protection.rb
+++ b/lib/axlsx/stylesheet/cell_protection.rb
@@ -26,9 +26,9 @@ module Axlsx
end
# @see hidden
- def hidden=(v) Axlsx::validate_boolean v; @hidden = v end
+ def hidden=(v) Axlsx.validate_boolean v; @hidden = v end
# @see locked
- def locked=(v) Axlsx::validate_boolean v; @locked = v end
+ def locked=(v) Axlsx.validate_boolean v; @locked = v end
# Serializes the object
# @param [String] str
diff --git a/lib/axlsx/stylesheet/cell_style.rb b/lib/axlsx/stylesheet/cell_style.rb
index 5cdb4842..3bc9faec 100644
--- a/lib/axlsx/stylesheet/cell_style.rb
+++ b/lib/axlsx/stylesheet/cell_style.rb
@@ -48,17 +48,17 @@ module Axlsx
attr_reader :customBuiltin
# @see name
- def name=(v) Axlsx::validate_string v; @name = v end
+ def name=(v) Axlsx.validate_string v; @name = v end
# @see xfId
- def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
+ def xfId=(v) Axlsx.validate_unsigned_int v; @xfId = v end
# @see builtinId
- def builtinId=(v) Axlsx::validate_unsigned_int v; @builtinId = v end
+ def builtinId=(v) Axlsx.validate_unsigned_int v; @builtinId = v end
# @see iLivel
- def iLevel=(v) Axlsx::validate_unsigned_int v; @iLevel = v end
+ def iLevel=(v) Axlsx.validate_unsigned_int v; @iLevel = v end
# @see hidden
- def hidden=(v) Axlsx::validate_boolean v; @hidden = v end
+ def hidden=(v) Axlsx.validate_boolean v; @hidden = v end
# @see customBuiltin
- def customBuiltin=(v) Axlsx::validate_boolean v; @customBuiltin = v end
+ def customBuiltin=(v) Axlsx.validate_boolean v; @customBuiltin = v end
# Serializes the object
# @param [String] str
diff --git a/lib/axlsx/stylesheet/color.rb b/lib/axlsx/stylesheet/color.rb
index 0c40a073..cfe5de9a 100644
--- a/lib/axlsx/stylesheet/color.rb
+++ b/lib/axlsx/stylesheet/color.rb
@@ -47,11 +47,11 @@ module Axlsx
attr_reader :tint
# @see auto
- def auto=(v) Axlsx::validate_boolean v; @auto = v end
+ def auto=(v) Axlsx.validate_boolean v; @auto = v end
# @see color
def rgb=(v)
- Axlsx::validate_string(v)
+ Axlsx.validate_string(v)
v = v.upcase
v *= 3 if v.size == 2
v = v.rjust(8, 'FF')
@@ -61,7 +61,7 @@ module Axlsx
end
# @see tint
- def tint=(v) Axlsx::validate_float v; @tint = v end
+ def tint=(v) Axlsx.validate_float v; @tint = v end
# This version does not support themes
# def theme=(v) Axlsx::validate_unsigned_integer v; @theme = v end
diff --git a/lib/axlsx/stylesheet/dxf.rb b/lib/axlsx/stylesheet/dxf.rb
index 2c10443a..dc9c2e1c 100644
--- a/lib/axlsx/stylesheet/dxf.rb
+++ b/lib/axlsx/stylesheet/dxf.rb
@@ -69,7 +69,7 @@ module Axlsx
# Dxf elements have no attributes. All of the instance variables
# are child elements.
CHILD_ELEMENTS.each do |element|
- self.send(element).to_xml_string(str) if self.send(element)
+ send(element).to_xml_string(str) if send(element)
end
str << '</dxf>'
end
diff --git a/lib/axlsx/stylesheet/font.rb b/lib/axlsx/stylesheet/font.rb
index 8b183b6e..bb80fbc2 100644
--- a/lib/axlsx/stylesheet/font.rb
+++ b/lib/axlsx/stylesheet/font.rb
@@ -112,38 +112,38 @@ module Axlsx
attr_reader :sz
# @see name
- def name=(v) Axlsx::validate_string v; @name = v end
+ def name=(v) Axlsx.validate_string v; @name = v end
# @see charset
- def charset=(v) Axlsx::validate_unsigned_int v; @charset = v end
+ def charset=(v) Axlsx.validate_unsigned_int v; @charset = v end
# @see family
- def family=(v) Axlsx::validate_unsigned_int v; @family = v end
+ def family=(v) Axlsx.validate_unsigned_int v; @family = v end
# @see b
- def b=(v) Axlsx::validate_boolean v; @b = v end
+ def b=(v) Axlsx.validate_boolean v; @b = v end
# @see i
- def i=(v) Axlsx::validate_boolean v; @i = v end
+ def i=(v) Axlsx.validate_boolean v; @i = v end
# @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')
- Axlsx::validate_cell_u v
+ 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
# @see strike
- def strike=(v) Axlsx::validate_boolean v; @strike = v end
+ def strike=(v) Axlsx.validate_boolean v; @strike = v end
# @see outline
- def outline=(v) Axlsx::validate_boolean v; @outline = v end
+ def outline=(v) Axlsx.validate_boolean v; @outline = v end
# @see shadow
- def shadow=(v) Axlsx::validate_boolean v; @shadow = v end
+ def shadow=(v) Axlsx.validate_boolean v; @shadow = v end
# @see condense
- def condense=(v) Axlsx::validate_boolean v; @condense = v end
+ def condense=(v) Axlsx.validate_boolean v; @condense = v end
# @see extend
- def extend=(v) Axlsx::validate_boolean v; @extend = v end
+ def extend=(v) Axlsx.validate_boolean v; @extend = v end
# @see color
def color=(v) DataTypeValidator.validate "Font.color", Color, v; @color = v end
# @see sz
- def sz=(v) Axlsx::validate_unsigned_int v; @sz = v end
+ def sz=(v) Axlsx.validate_unsigned_int v; @sz = v end
# Serializes the object
# @param [String] str
diff --git a/lib/axlsx/stylesheet/gradient_fill.rb b/lib/axlsx/stylesheet/gradient_fill.rb
index 6cd0a052..508c91a2 100644
--- a/lib/axlsx/stylesheet/gradient_fill.rb
+++ b/lib/axlsx/stylesheet/gradient_fill.rb
@@ -55,10 +55,10 @@ module Axlsx
attr_reader :stop
# @see type
- def type=(v) Axlsx::validate_gradient_type v; @type = v end
+ def type=(v) Axlsx.validate_gradient_type v; @type = v end
# @see degree
- def degree=(v) Axlsx::validate_float v; @degree = v end
+ def degree=(v) Axlsx.validate_float v; @degree = v end
# @see left
def left=(v)
@@ -86,7 +86,7 @@ module Axlsx
# validates that the value provided is between 0.0 and 1.0
def validate_format_percentage(name, value)
- DataTypeValidator.validate name, Float, value, lambda { |arg| arg >= 0.0 && arg <= 1.0 }
+ DataTypeValidator.validate name, Float, value, ->(arg) { arg >= 0.0 && arg <= 1.0 }
end
# Serializes the object
diff --git a/lib/axlsx/stylesheet/gradient_stop.rb b/lib/axlsx/stylesheet/gradient_stop.rb
index dd0ea00f..d4df9b3b 100644
--- a/lib/axlsx/stylesheet/gradient_stop.rb
+++ b/lib/axlsx/stylesheet/gradient_stop.rb
@@ -24,14 +24,14 @@ module Axlsx
# @see color
def color=(v) DataTypeValidator.validate "GradientStop.color", Color, v; @color = v end
# @see position
- def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, lambda { |arg| arg >= 0 && arg <= 1 }; @position = v end
+ def position=(v) DataTypeValidator.validate "GradientStop.position", Float, v, ->(arg) { arg >= 0 && arg <= 1 }; @position = v end
# Serializes the object
# @param [String] str
# @return [String]
def to_xml_string(str = +'')
str << '<stop position="' << position.to_s << '">'
- self.color.to_xml_string(str)
+ color.to_xml_string(str)
str << '</stop>'
end
end
diff --git a/lib/axlsx/stylesheet/num_fmt.rb b/lib/axlsx/stylesheet/num_fmt.rb
index 4604d7bd..e49ec574 100644
--- a/lib/axlsx/stylesheet/num_fmt.rb
+++ b/lib/axlsx/stylesheet/num_fmt.rb
@@ -61,10 +61,10 @@ module Axlsx
attr_reader :numFmtId
# @see numFmtId
- def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
+ def numFmtId=(v) Axlsx.validate_unsigned_int v; @numFmtId = v end
# @see formatCode
- def formatCode=(v) Axlsx::validate_string v; @formatCode = v end
+ def formatCode=(v) Axlsx.validate_string v; @formatCode = v end
# Serializes the object
# @param [String] str
diff --git a/lib/axlsx/stylesheet/pattern_fill.rb b/lib/axlsx/stylesheet/pattern_fill.rb
index 9f92dc00..ec920ab3 100644
--- a/lib/axlsx/stylesheet/pattern_fill.rb
+++ b/lib/axlsx/stylesheet/pattern_fill.rb
@@ -53,7 +53,7 @@ module Axlsx
# @see bgColor
def bgColor=(v) DataTypeValidator.validate "PatternFill.bgColor", Color, v; @bgColor = v end
# @see patternType
- def patternType=(v) Axlsx::validate_pattern_type v; @patternType = v end
+ def patternType=(v) Axlsx.validate_pattern_type v; @patternType = v end
# Serializes the object
# @param [String] str
diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb
index e518d21e..d9c5683a 100644
--- a/lib/axlsx/stylesheet/styles.rb
+++ b/lib/axlsx/stylesheet/styles.rb
@@ -370,7 +370,7 @@ module Axlsx
if options[:border].is_a?(Integer)
if options[:border] >= borders.size
- raise ArgumentError, (ERR_INVALID_BORDER_ID % options[:border])
+ raise ArgumentError, format(ERR_INVALID_BORDER_ID, options[:border])
end
if options[:type] == :dxf
@@ -380,9 +380,9 @@ module Axlsx
end
end
- validate_border_hash = ->(val) {
- if !(val.key?(:style) && val.key?(:color))
- raise ArgumentError, (ERR_INVALID_BORDER_OPTIONS % options[:border])
+ validate_border_hash = lambda { |val|
+ unless val.key?(:style) && val.key?(:color)
+ raise ArgumentError, format(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/stylesheet/table_style.rb b/lib/axlsx/stylesheet/table_style.rb
index 3c3837ea..95d10ce0 100644
--- a/lib/axlsx/stylesheet/table_style.rb
+++ b/lib/axlsx/stylesheet/table_style.rb
@@ -33,18 +33,18 @@ module Axlsx
attr_reader :table
# @see name
- def name=(v) Axlsx::validate_string v; @name = v end
+ def name=(v) Axlsx.validate_string v; @name = v end
# @see pivot
- def pivot=(v) Axlsx::validate_boolean v; @pivot = v end
+ def pivot=(v) Axlsx.validate_boolean v; @pivot = v end
# @see table
- def table=(v) Axlsx::validate_boolean v; @table = v end
+ def table=(v) Axlsx.validate_boolean v; @table = v end
# Serializes the object
# @param [String] str
# @return [String]
def to_xml_string(str = +'')
str << '<tableStyle '
- serialized_attributes str, { count: self.size }
+ serialized_attributes str, { count: size }
str << '>'
each { |table_style_el| table_style_el.to_xml_string(str) }
str << '</tableStyle>'
diff --git a/lib/axlsx/stylesheet/table_style_element.rb b/lib/axlsx/stylesheet/table_style_element.rb
index 2e64d9a3..281a819e 100644
--- a/lib/axlsx/stylesheet/table_style_element.rb
+++ b/lib/axlsx/stylesheet/table_style_element.rb
@@ -58,13 +58,13 @@ module Axlsx
attr_reader :dxfId
# @see type
- def type=(v) Axlsx::validate_table_element_type v; @type = v end
+ def type=(v) Axlsx.validate_table_element_type v; @type = v end
# @see size
- def size=(v) Axlsx::validate_unsigned_int v; @size = v end
+ def size=(v) Axlsx.validate_unsigned_int v; @size = v end
# @see dxfId
- def dxfId=(v) Axlsx::validate_unsigned_int v; @dxfId = v end
+ def dxfId=(v) Axlsx.validate_unsigned_int v; @dxfId = v end
# Serializes the object
# @param [String] str
diff --git a/lib/axlsx/stylesheet/table_styles.rb b/lib/axlsx/stylesheet/table_styles.rb
index 38a6eb45..fec2a0f6 100644
--- a/lib/axlsx/stylesheet/table_styles.rb
+++ b/lib/axlsx/stylesheet/table_styles.rb
@@ -26,16 +26,16 @@ module Axlsx
attr_reader :defaultPivotStyle
# @see defaultTableStyle
- def defaultTableStyle=(v) Axlsx::validate_string(v); @defaultTableStyle = v; end
+ def defaultTableStyle=(v) Axlsx.validate_string(v); @defaultTableStyle = v; end
# @see defaultPivotStyle
- def defaultPivotStyle=(v) Axlsx::validate_string(v); @defaultPivotStyle = v; end
+ def defaultPivotStyle=(v) Axlsx.validate_string(v); @defaultPivotStyle = v; end
# Serializes the object
# @param [String] str
# @return [String]
def to_xml_string(str = +'')
str << '<tableStyles '
- serialized_attributes str, { count: self.size }
+ serialized_attributes str, { count: size }
str << '>'
each { |table_style| table_style.to_xml_string(str) }
str << '</tableStyles>'
diff --git a/lib/axlsx/stylesheet/xf.rb b/lib/axlsx/stylesheet/xf.rb
index 45d362ca..0ea97f20 100644
--- a/lib/axlsx/stylesheet/xf.rb
+++ b/lib/axlsx/stylesheet/xf.rb
@@ -101,35 +101,35 @@ module Axlsx
def protection=(v) DataTypeValidator.validate "Xf.protection", CellProtection, v; @protection = v end
# @see numFmtId
- def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
+ def numFmtId=(v) Axlsx.validate_unsigned_int v; @numFmtId = v end
# @see fontId
- def fontId=(v) Axlsx::validate_unsigned_int v; @fontId = v end
+ def fontId=(v) Axlsx.validate_unsigned_int v; @fontId = v end
# @see fillId
- def fillId=(v) Axlsx::validate_unsigned_int v; @fillId = v end
+ def fillId=(v) Axlsx.validate_unsigned_int v; @fillId = v end
# @see borderId
- def borderId=(v) Axlsx::validate_unsigned_int v; @borderId = v end
+ def borderId=(v) Axlsx.validate_unsigned_int v; @borderId = v end
# @see xfId
- def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
+ def xfId=(v) Axlsx.validate_unsigned_int v; @xfId = v end
# @see quotePrefix
- def quotePrefix=(v) Axlsx::validate_boolean v; @quotePrefix = v end
+ def quotePrefix=(v) Axlsx.validate_boolean v; @quotePrefix = v end
# @see pivotButton
- def pivotButton=(v) Axlsx::validate_boolean v; @pivotButton = v end
+ def pivotButton=(v) Axlsx.validate_boolean v; @pivotButton = v end
# @see applyNumberFormat
- def applyNumberFormat=(v) Axlsx::validate_boolean v; @applyNumberFormat = v end
+ def applyNumberFormat=(v) Axlsx.validate_boolean v; @applyNumberFormat = v end
# @see applyFont
- def applyFont=(v) Axlsx::validate_boolean v; @applyFont = v end
+ def applyFont=(v) Axlsx.validate_boolean v; @applyFont = v end
# @see applyFill
- def applyFill=(v) Axlsx::validate_boolean v; @applyFill = v end
+ def applyFill=(v) Axlsx.validate_boolean v; @applyFill = v end
# @see applyBorder
- def applyBorder=(v) Axlsx::validate_boolean v; @applyBorder = v end
+ def applyBorder=(v) Axlsx.validate_boolean v; @applyBorder = v end
# @see applyAlignment
- def applyAlignment=(v) Axlsx::validate_boolean v; @applyAlignment = v end
+ def applyAlignment=(v) Axlsx.validate_boolean v; @applyAlignment = v end
# @see applyProtection
- def applyProtection=(v) Axlsx::validate_boolean v; @applyProtection = v end
+ def applyProtection=(v) Axlsx.validate_boolean v; @applyProtection = v end
# Serializes the object
# @param [String] str
@@ -138,8 +138,8 @@ module Axlsx
str << '<xf '
serialized_attributes str
str << '>'
- alignment.to_xml_string(str) if self.alignment
- protection.to_xml_string(str) if self.protection
+ alignment.to_xml_string(str) if alignment
+ protection.to_xml_string(str) if protection
str << '</xf>'
end
end
diff --git a/lib/axlsx/util/accessors.rb b/lib/axlsx/util/accessors.rb
index d653e32f..dfc3b1cd 100644
--- a/lib/axlsx/util/accessors.rb
+++ b/lib/axlsx/util/accessors.rb
@@ -56,7 +56,7 @@ module Axlsx
symbols.each do |symbol|
attr_reader symbol
- module_eval(SETTER % [symbol, validator, symbol], __FILE__, __LINE__)
+ module_eval(format(SETTER, symbol, validator, symbol), __FILE__, __LINE__)
end
end
end
diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb
index 0767be31..70951eb8 100644
--- a/lib/axlsx/util/constants.rb
+++ b/lib/axlsx/util/constants.rb
@@ -397,9 +397,8 @@ module Axlsx
# x0A Line Feed (Lf)
# x0D Carriage Return (Cr)
# x09 Character Tabulation
- # @see http://www.codetable.net/asciikeycodes
- pattern = "\x0-\x08\x0B\x0C\x0E-\x1F"
- pattern = pattern.respond_to?(:encode) ? pattern.encode('UTF-8') : pattern
+ # @see https://www.codetable.net/asciikeycodes
+ pattern = "\x0-\x08\x0B\x0C\x0E-\x1F".encode(Encoding::UTF_8)
# The regular expression used to remove control characters from worksheets
CONTROL_CHARS = pattern.freeze
diff --git a/lib/axlsx/util/options_parser.rb b/lib/axlsx/util/options_parser.rb
index 526a3aed..73faa224 100644
--- a/lib/axlsx/util/options_parser.rb
+++ b/lib/axlsx/util/options_parser.rb
@@ -10,7 +10,7 @@ module Axlsx
def parse_options(options = {})
options.each do |key, value|
key = :"#{key}="
- self.send(key, value) if !value.nil? && self.respond_to?(key)
+ send(key, value) if !value.nil? && respond_to?(key)
end
end
end
diff --git a/lib/axlsx/util/storage.rb b/lib/axlsx/util/storage.rb
index b33c499d..ac5e9ebc 100644
--- a/lib/axlsx/util/storage.rb
+++ b/lib/axlsx/util/storage.rb
@@ -75,7 +75,7 @@ module Axlsx
# @param [String] v The data for this storages stream
# @return [Array]
def data=(v)
- Axlsx::validate_string(v)
+ Axlsx.validate_string(v)
self.type = TYPES[:stream] unless @type
@size = v.size
@data = v.bytes.to_a
@@ -133,7 +133,7 @@ module Axlsx
@left = @right = @child = -1
@sector = @size = @created = @modified = 0
options.each do |o|
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
+ send("#{o[0]}=", o[1]) if respond_to? "#{o[0]}="
end
@color ||= COLORS[:black]
@type ||= (data.nil? ? TYPES[:storage] : TYPES[:stream])
diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb
index 695d28ad..5684c9cb 100644
--- a/lib/axlsx/util/validators.rb
+++ b/lib/axlsx/util/validators.rb
@@ -10,7 +10,7 @@ module Axlsx
# @raise [ArgumentError] Raised if the value provided is not in the list of choices.
# @return [Boolean] true if validation succeeds.
def self.validate(name, choices, v)
- raise ArgumentError, (ERR_RESTRICTION % [v.to_s, name, choices.inspect]) unless choices.include?(v)
+ raise ArgumentError, format(ERR_RESTRICTION, v.to_s, name, choices.inspect) unless choices.include?(v)
true
end
@@ -31,7 +31,7 @@ module Axlsx
else
min < value && value < max
end
- raise ArgumentError, (ERR_RANGE % [value.inspect, min.to_s, max.to_s, inclusive]) unless passes
+ raise ArgumentError, format(ERR_RANGE, value.inspect, min.to_s, max.to_s, inclusive) unless passes
end
end
@@ -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, format(ERR_REGEX, v.inspect, regex.to_s) unless v.respond_to?(:to_s) && regex.match?(v.to_s)
end
end
@@ -56,14 +56,13 @@ module Axlsx
# @see validate_boolean
def self.validate(name, types, v, other = false)
if other.is_a?(Proc) && !other.call(v)
- raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect])
+ raise ArgumentError, format(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
- end
- raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect])
+ return if Array(types).any? { |t| v_class <= t }
+
+ raise ArgumentError, format(ERR_TYPE, v.inspect, name, types.inspect)
end
end
@@ -71,7 +70,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, format(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,11 +78,11 @@ 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, format(ERR_ANGLE, v.inspect) unless v.to_i >= -5400000 && v.to_i <= 5400000
end
# Validates an unsigned intger
- UINT_VALIDATOR = lambda { |arg| arg.respond_to?(:>=) && arg >= 0 }
+ UINT_VALIDATOR = ->(arg) { arg.respond_to?(:>=) && arg >= 0 }
# Requires that the value is a Integer and is greater or equal to 0
# @param [Any] v The value validated
@@ -109,7 +108,7 @@ module Axlsx
VALID_BOOLEAN_CLASSES = [TrueClass, FalseClass, Integer, String, Symbol].freeze
VALID_BOOLEAN_VALUES = [true, false, 1, 0, '1', '0', 'true', 'false', :true, :false].freeze
- BOOLEAN_VALIDATOR = lambda { |arg| VALID_BOOLEAN_VALUES.include?(arg) }
+ BOOLEAN_VALIDATOR = ->(arg) { VALID_BOOLEAN_VALUES.include?(arg) }
# Requires that the value is a form that can be evaluated as a boolean in an xml document.
# The value must be an instance of String, Integer, Symbol, TrueClass or FalseClass and
@@ -137,14 +136,14 @@ module Axlsx
RegexValidator.validate "number_with_unit", /\A[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)\Z/, v
end
- SCALE_10_400_VALIDATOR = lambda { |arg| arg >= 10 && arg <= 400 }
+ SCALE_10_400_VALIDATOR = ->(arg) { arg >= 10 && arg <= 400 }
# Requires that the value is an integer ranging from 10 to 400.
def self.validate_scale_10_400(v)
DataTypeValidator.validate "page_scale", Integer, v, SCALE_10_400_VALIDATOR
end
- SCALE_0_10_400_VALIDATOR = lambda { |arg| arg == 0 || (arg >= 10 && arg <= 400) }
+ SCALE_0_10_400_VALIDATOR = ->(arg) { arg == 0 || (arg >= 10 && arg <= 400) }
# Requires that the value is an integer ranging from 10 to 400 or 0.
def self.validate_scale_0_10_400(v)
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/defined_name.rb b/lib/axlsx/workbook/defined_name.rb
index 38669076..3f6a4cae 100644
--- a/lib/axlsx/workbook/defined_name.rb
+++ b/lib/axlsx/workbook/defined_name.rb
@@ -109,7 +109,7 @@ module Axlsx
# The local sheet index (0-based)
# @param [Integer] value the unsigned integer index of the sheet this defined_name applies to.
def local_sheet_id=(value)
- Axlsx::validate_unsigned_int(value)
+ Axlsx.validate_unsigned_int(value)
@local_sheet_id = value
end
diff --git a/lib/axlsx/workbook/shared_strings_table.rb b/lib/axlsx/workbook/shared_strings_table.rb
index a8086f3e..ad4084ff 100644
--- a/lib/axlsx/workbook/shared_strings_table.rb
+++ b/lib/axlsx/workbook/shared_strings_table.rb
@@ -46,7 +46,7 @@ module Axlsx
# @param [String] str
# @return [String]
def to_xml_string(str = +'')
- Axlsx::sanitize(@shared_xml_string)
+ Axlsx.sanitize(@shared_xml_string)
str << '<?xml version="1.0" encoding="UTF-8"?><sst xmlns="' << XML_NS << '"'
str << ' count="' << @count.to_s << '" uniqueCount="' << unique_count.to_s << '"'
str << ' xml:space="' << xml_space.to_s << '">' << @shared_xml_string << '</sst>'
diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb
index e6e2f06f..5f6dcff7 100644
--- a/lib/axlsx/workbook/workbook.rb
+++ b/lib/axlsx/workbook/workbook.rb
@@ -95,7 +95,7 @@ module Axlsx
# @see use_shared_strings
def use_shared_strings=(v)
- Axlsx::validate_boolean(v)
+ Axlsx.validate_boolean(v)
@use_shared_strings = v
end
@@ -104,7 +104,7 @@ module Axlsx
attr_reader :is_reversed
def is_reversed=(v)
- Axlsx::validate_boolean(v)
+ Axlsx.validate_boolean(v)
@is_reversed = v
end
@@ -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]
@@ -252,11 +252,11 @@ module Axlsx
def date1904() @@date1904; end
# see @date1904
- def date1904=(v) Axlsx::validate_boolean v; @@date1904 = v; end
+ def date1904=(v) Axlsx.validate_boolean v; @@date1904 = v; end
# Sets the date1904 attribute to the provided boolean
# @return [Boolean]
- def self.date1904=(v) Axlsx::validate_boolean v; @@date1904 = v; end
+ def self.date1904=(v) Axlsx.validate_boolean v; @@date1904 = v; end
# retrieves the date1904 attribute
# @return [Boolean]
@@ -283,7 +283,7 @@ module Axlsx
def use_autowidth() @use_autowidth; end
# see @use_autowidth
- def use_autowidth=(v = true) Axlsx::validate_boolean v; @use_autowidth = v; end
+ def use_autowidth=(v = true) Axlsx.validate_boolean v; @use_autowidth = v; end
# Font size of bold fonts is multiplied with this
# Used for automatic calculation of cell widths with bold text
@@ -291,7 +291,7 @@ module Axlsx
attr_reader :bold_font_multiplier
def bold_font_multiplier=(v)
- Axlsx::validate_float v
+ Axlsx.validate_float v
@bold_font_multiplier = v
end
@@ -301,7 +301,7 @@ module Axlsx
attr_reader :font_scale_divisor
def font_scale_divisor=(v)
- Axlsx::validate_float v
+ Axlsx.validate_float v
@font_scale_divisor = v
end
@@ -354,10 +354,10 @@ module Axlsx
def relationships
r = Relationships.new
@worksheets.each do |sheet|
- r << Relationship.new(sheet, WORKSHEET_R, WORKSHEET_PN % (r.size + 1))
+ r << Relationship.new(sheet, WORKSHEET_R, format(WORKSHEET_PN, r.size + 1))
end
pivot_tables.each_with_index do |pivot_table, index|
- r << Relationship.new(pivot_table.cache_definition, PIVOT_TABLE_CACHE_DEFINITION_R, PIVOT_TABLE_CACHE_DEFINITION_PN % (index + 1))
+ r << Relationship.new(pivot_table.cache_definition, PIVOT_TABLE_CACHE_DEFINITION_R, format(PIVOT_TABLE_CACHE_DEFINITION_PN, index + 1))
end
r << Relationship.new(self, STYLES_R, STYLES_PN)
if use_shared_strings
@@ -396,7 +396,7 @@ module Axlsx
# @return [Cell, Array]
def [](cell_def)
sheet_name = cell_def.split('!')[0] if cell_def.include?('!')
- worksheet = self.worksheets.find { |s| s.name == sheet_name }
+ worksheet = worksheets.find { |s| s.name == sheet_name }
raise ArgumentError, 'Unknown Sheet' unless sheet_name && worksheet.is_a?(Worksheet)
worksheet[cell_def.gsub(/.+!/, "")]
diff --git a/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb b/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb
index f25966de..586dc711 100644
--- a/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb
+++ b/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb
@@ -2,6 +2,7 @@
require 'axlsx/workbook/worksheet/auto_filter/filter_column'
require 'axlsx/workbook/worksheet/auto_filter/filters'
+require 'axlsx/workbook/worksheet/auto_filter/sort_state'
module Axlsx
# This class represents an auto filter range in a worksheet
@@ -12,9 +13,10 @@ module Axlsx
raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet)
@worksheet = worksheet
+ @sort_on_generate = true
end
- attr_reader :worksheet
+ attr_reader :worksheet, :sort_on_generate
# The range the autofilter should be applied to.
# This should be a string like 'A1:B8'
@@ -48,15 +50,50 @@ module Axlsx
columns.last
end
- # actually performs the filtering of rows who's cells do not
- # match the filter.
+ # Performs the sorting of the rows based on the sort_state conditions. Then it actually performs
+ # the filtering of rows who's cells do not match the filter.
def apply
first_cell, last_cell = range.split(':')
- start_point = Axlsx::name_to_indices(first_cell)
- end_point = Axlsx::name_to_indices(last_cell)
+ start_point = Axlsx.name_to_indices(first_cell)
+ end_point = Axlsx.name_to_indices(last_cell)
# The +1 is so we skip the header row with the filter drop downs
rows = worksheet.rows[(start_point.last + 1)..end_point.last] || []
+ # the sorting of the rows if sort_conditions are available.
+ if !sort_state.sort_conditions.empty? && sort_on_generate
+ sort_conditions = sort_state.sort_conditions
+ sorted_rows = rows.sort do |row1, row2|
+ comparison = 0
+
+ sort_conditions.each do |condition|
+ cell_value_row1 = row1.cells[condition.column_index + start_point.first].value
+ cell_value_row2 = row2.cells[condition.column_index + start_point.first].value
+ custom_list = condition.custom_list
+ comparison = if cell_value_row1.nil? || cell_value_row2.nil?
+ cell_value_row1.nil? ? 1 : -1
+ elsif custom_list.empty?
+ condition.order == :asc ? cell_value_row1 <=> cell_value_row2 : cell_value_row2 <=> cell_value_row1
+ else
+ index1 = custom_list.index(cell_value_row1) || custom_list.size
+ index2 = custom_list.index(cell_value_row2) || custom_list.size
+
+ condition.order == :asc ? index1 <=> index2 : index2 <=> index1
+ end
+
+ break unless comparison.zero?
+ end
+
+ comparison
+ end
+ insert_index = start_point.last + 1
+
+ sorted_rows.each do |row|
+ # Insert the row at the specified index
+ worksheet.rows[insert_index] = row
+ insert_index += 1
+ end
+ end
+
column_offset = start_point.first
columns.each do |column|
rows.each do |row|
@@ -67,6 +104,21 @@ module Axlsx
end
end
+ # the SortState object for this AutoFilter
+ # @return [SortState]
+ def sort_state
+ @sort_state ||= SortState.new self
+ end
+
+ # @param [Boolean] v Flag indicating whether the AutoFilter should sort the rows when generating the
+ # file. If false, the sorting rules will need to be applied manually after generating to alter
+ # the order of the rows.
+ # @return [Boolean]
+ def sort_on_generate=(v)
+ Axlsx.validate_boolean v
+ @sort_on_generate = v
+ end
+
# serialize the object
# @return [String]
def to_xml_string(str = +'')
@@ -74,6 +126,9 @@ module Axlsx
str << "<autoFilter ref='#{range}'>"
columns.each { |filter_column| filter_column.to_xml_string(str) }
+ unless @sort_state.nil?
+ @sort_state.to_xml_string(str)
+ end
str << "</autoFilter>"
end
end
diff --git a/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb b/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb
new file mode 100644
index 00000000..8704dbdd
--- /dev/null
+++ b/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+module Axlsx
+ # This class represents a individual sort condition belonging to the sort state of an auto filter
+ class SortCondition
+ # Creates a new SortCondition object
+ # @param [Integer] column_index Zero-based index indicating the AutoFilter column to which the sorting should be applied to
+ # @param [Symbol] order The order the column should be sorted on, can only be :asc or :desc
+ # @param [Array] custom_list An array containg a custom sorting list in order.
+ def initialize(column_index:, order:, custom_list:)
+ Axlsx.validate_int column_index
+ @column_index = column_index
+
+ RestrictionValidator.validate 'SortCondition.order', [:asc, :desc], order
+ @order = order
+
+ DataTypeValidator.validate :sort_condition_custom_list, Array, custom_list
+ @custom_list = custom_list
+ end
+
+ attr_reader :column_index, :order, :custom_list
+
+ # converts the ref String from the sort_state to a string representing the ref of a single column
+ # for the xml string to be returned.
+ def ref_to_single_column(ref, column_index)
+ first_cell, last_cell = ref.split(':')
+
+ start_point = Axlsx.name_to_indices(first_cell)
+
+ first_row = first_cell[/\d+/]
+ last_row = last_cell[/\d+/]
+
+ first_column = Axlsx.col_ref(column_index + start_point.first)
+ last_column = first_column
+
+ "#{first_column}#{first_row}:#{last_column}#{last_row}"
+ end
+
+ # serialize the object
+ # @return [String]
+ def to_xml_string(str, ref)
+ ref = ref_to_single_column(ref, column_index)
+
+ str << "<sortCondition "
+ str << "descending='1' " if order == :desc
+ str << "ref='#{ref}' "
+ str << "customList='#{custom_list.join(',')}' " unless custom_list.empty?
+ str << "/>"
+ end
+ end
+end
diff --git a/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb b/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb
new file mode 100644
index 00000000..71e03b00
--- /dev/null
+++ b/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+require 'axlsx/workbook/worksheet/auto_filter/sort_condition'
+
+module Axlsx
+ # This class performs sorting on a range in a worksheet
+ class SortState
+ # creates a new SortState object
+ # @param [AutoFilter] auto_filter the auto_filter that this sort_state belongs to
+ def initialize(auto_filter)
+ @auto_filter = auto_filter
+ end
+
+ # A collection of SortConditions for this sort_state
+ # @return [SimpleTypedList]
+ def sort_conditions
+ @sort_conditions ||= SimpleTypedList.new SortCondition
+ end
+
+ # Adds a SortCondition to the sort_state. This is the recommended way to add conditions to it.
+ # It requires a column_index for the sorting, descending and the custom order are optional.
+ # @param [Integer] column_index Zero-based index indicating the AutoFilter column to which the sorting should be applied to
+ # @param [Symbol] order The order the column should be sorted on, can only be :asc or :desc
+ # @param [Array] custom_list An array containg a custom sorting list in order.
+ # @return [SortCondition]
+ def add_sort_condition(column_index:, order: :asc, custom_list: [])
+ sort_conditions << SortCondition.new(column_index: column_index, order: order, custom_list: custom_list)
+ sort_conditions.last
+ end
+
+ # method to increment the String representing the first cell of the range of the autofilter by 1 row for the sortCondition
+ # xml string
+ def increment_cell_value(str)
+ letter = str[/[A-Za-z]+/]
+ number = str[/\d+/].to_i
+
+ incremented_number = number + 1
+
+ "#{letter}#{incremented_number}"
+ end
+
+ # serialize the object
+ # @return [String]
+ def to_xml_string(str = +'')
+ return if sort_conditions.empty?
+
+ ref = @auto_filter.range
+ first_cell, last_cell = ref.split(':')
+ ref = "#{increment_cell_value(first_cell)}:#{last_cell}"
+
+ str << "<sortState xmlns:xlrd2='http://schemas.microsoft.com/office/spreadsheetml/2017/richdata2' ref='#{ref}'>"
+ sort_conditions.each { |sort_condition| sort_condition.to_xml_string(str, ref) }
+ str << "</sortState>"
+ end
+ end
+end
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/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index f651e3cb..2ff3a3cc 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -1,6 +1,5 @@
# frozen_string_literal: true
-require 'cgi'
module Axlsx
# A cell in a worksheet.
# Cell stores inforamation requried to serialize a single worksheet cell to xml. You must provde the Row that the cell belongs to and the cells value. The data type will automatically be determed if you do not specify the :type option. The default style will be applied if you do not supply the :style option. Changing the cell's type will recast the value to the type specified. Altering the cell's value via the property accessor will also automatically cast the provided value to the cell's type.
@@ -48,7 +47,7 @@ module Axlsx
val = options.delete(:escape_formulas)
self.escape_formulas = val unless val.nil?
- parse_options(options)
+ parse_options(options) unless options.empty?
self.value = value
value.cell = self if contains_rich_text?
@@ -167,7 +166,7 @@ module Axlsx
# Indicates that the cell has one or more of the custom cell styles applied.
# @return [Boolean]
- def is_text_run?
+ def is_text_run? # rubocop:disable Naming/PredicateName
defined?(@is_text_run) && @is_text_run && !contains_rich_text?
end
@@ -177,12 +176,12 @@ module Axlsx
# Indicates if the cell is good for shared string table
def plain_string?
- (type == :string || type == :text) && # String typed
- !is_text_run? && # No inline styles
- [email protected]? && # Not nil
- [email protected]? && # Not empty
- !is_formula? && # Not a formula
- !is_array_formula? # Not an array formula
+ (type == :string || type == :text) && # String typed
+ !value.nil? &&
+ !value.empty? &&
+ !is_text_run? && # No inline styles
+ !is_formula? &&
+ !is_array_formula?
end
# The inline font_name property for the cell
@@ -345,7 +344,7 @@ module Axlsx
# @example Relative Cell Reference
# ws.rows.first.cells.first.r #=> "A1"
def r
- Axlsx::cell_r index, @row.row_index
+ Axlsx.cell_r index, @row.row_index
end
# @return [String] The absolute alpha(column)numeric(row) reference for this cell.
@@ -358,7 +357,7 @@ module Axlsx
# @return [Integer] The cellXfs item index applied to this cell.
# @raise [ArgumentError] Invalid cellXfs id if the value provided is not within cellXfs items range.
def style=(v)
- Axlsx::validate_unsigned_int(v)
+ Axlsx.validate_unsigned_int(v)
count = styles.cellXfs.size
raise ArgumentError, "Invalid cellXfs id" unless v < count
@@ -375,11 +374,11 @@ module Axlsx
# @param [Cell, String] target The last cell, or str ref for the cell in the merge range
def merge(target)
start, stop = if target.is_a?(String)
- [self.r, target]
+ [r, target]
elsif target.is_a?(Cell)
Axlsx.sort_cells([self, target]).map(&:r)
end
- self.row.worksheet.merge_cells "#{start}:#{stop}" unless stop.nil?
+ row.worksheet.merge_cells "#{start}:#{stop}" unless stop.nil?
end
# Serializes the cell
@@ -391,13 +390,13 @@ module Axlsx
CellSerializer.to_xml_string r_index, c_index, self, str
end
- def is_formula?
+ def is_formula? # rubocop:disable Naming/PredicateName
return false if escape_formulas
type == :string && @value.to_s.start_with?(FORMULA_PREFIX)
end
- def is_array_formula?
+ def is_array_formula? # rubocop:disable Naming/PredicateName
return false if escape_formulas
type == :string &&
@@ -426,7 +425,7 @@ module Axlsx
# Attempts to determine the correct width for this cell's content
# @return [Float]
def autowidth
- return if is_formula? || value.nil?
+ return if value.nil? || is_formula?
if contains_rich_text?
string_width('', font_size) + value.autowidth
@@ -442,12 +441,13 @@ module Axlsx
end
end
- # Returns the sanatized value
- # TODO find a better way to do this as it accounts for 30% of
+ # Returns the sanitized value
+ # TODO: find a better way to do this as it accounts for 30% of
# processing time in benchmarking...
+ # @return [String] The sanitized value
def clean_value
- if (type == :string || type == :text) && !Axlsx::trust_input
- Axlsx::sanitize(::CGI.escapeHTML(@value.to_s))
+ if (type == :string || type == :text) && !Axlsx.trust_input
+ Axlsx.sanitize(::CGI.escapeHTML(@value.to_s))
else
@value.to_s
end
@@ -482,13 +482,13 @@ module Axlsx
return unless INLINE_STYLES.include?(attr.to_sym)
Axlsx.send(validator, value) unless validator.nil?
- self.instance_variable_set :"@#{attr}", value
+ instance_variable_set :"@#{attr}", value
@is_text_run = true
end
# @see ssti
def ssti=(v)
- Axlsx::validate_unsigned_int(v)
+ Axlsx.validate_unsigned_int(v)
@ssti = v
end
@@ -525,18 +525,18 @@ module Axlsx
# About Time - Time in OOXML is *different* from what you might expect. The history as to why is interesting, but you can safely assume that if you are generating docs on a mac, you will want to specify Workbook.1904 as true when using time typed values.
# @see Axlsx#date1904
def cast_value(v)
- return v if v.is_a?(RichText) || v.nil?
+ return v if v.nil? || v.is_a?(RichText)
case type
when :date
- self.style = STYLE_DATE if self.style.zero?
+ self.style = STYLE_DATE if style.zero?
if !v.is_a?(Date) && v.respond_to?(:to_date)
v.to_date
else
v
end
when :time
- self.style = STYLE_DATE if self.style.zero?
+ self.style = STYLE_DATE if style.zero?
if !v.is_a?(Time) && v.respond_to?(:to_time)
v.to_time
else
diff --git a/lib/axlsx/workbook/worksheet/cell_serializer.rb b/lib/axlsx/workbook/worksheet/cell_serializer.rb
index 30a2b5fe..2124a7f4 100644
--- a/lib/axlsx/workbook/worksheet/cell_serializer.rb
+++ b/lib/axlsx/workbook/worksheet/cell_serializer.rb
@@ -11,12 +11,12 @@ module Axlsx
# @return [String]
def to_xml_string(row_index, column_index, cell, str = +'')
str << '<c r="'
- str << Axlsx::col_ref(column_index) << Axlsx::row_ref(row_index)
+ str << Axlsx.col_ref(column_index) << Axlsx.row_ref(row_index)
str << '" s="' << cell.style_str << '" '
return str << '/>' if cell.value.nil?
method = cell.type
- self.send(method, cell, str)
+ send(method, cell, str)
str << '</c>'
end
@@ -27,7 +27,7 @@ module Axlsx
if cell.is_text_run?
valid = RichTextRun::INLINE_STYLES - [:value, :type]
data = Axlsx.instance_values_for(cell).transform_keys(&:to_sym)
- data = data.select { |key, value| valid.include?(key) && !value.nil? }
+ data = data.select { |key, value| !value.nil? && valid.include?(key) }
RichText.new(cell.value.to_s, data).to_xml_string(str)
elsif cell.contains_rich_text?
cell.value.to_xml_string(str)
@@ -50,7 +50,7 @@ module Axlsx
# @param [String] str The string the serialized content will be appended to.
# @return [String]
def date(cell, str = +'')
- value_serialization false, DateTimeConverter::date_to_serial(cell.value).to_s, str
+ value_serialization false, DateTimeConverter.date_to_serial(cell.value).to_s, str
end
# Serializes cells that are type time
@@ -58,7 +58,7 @@ module Axlsx
# @param [String] str The string the serialized content will be appended to.
# @return [String]
def time(cell, str = +'')
- value_serialization false, DateTimeConverter::time_to_serial(cell.value).to_s, str
+ value_serialization false, DateTimeConverter.time_to_serial(cell.value).to_s, str
end
# Serializes cells that are type boolean
@@ -90,7 +90,7 @@ module Axlsx
# @param [String] str The string the serialized content will be appended to.
# @return [String]
def formula_serialization(cell, str = +'')
- str << 't="str"><f>' << cell.clean_value.to_s.delete_prefix(FORMULA_PREFIX) << '</f>'
+ str << 't="str"><f>' << cell.clean_value.delete_prefix(FORMULA_PREFIX) << '</f>'
str << '<v>' << cell.formula_value.to_s << '</v>' unless cell.formula_value.nil?
end
@@ -99,7 +99,7 @@ module Axlsx
# @param [String] str The string the serialized content will be appended to.
# @return [String]
def array_formula_serialization(cell, str = +'')
- str << 't="str">' << '<f t="array" ref="' << cell.r << '">' << cell.clean_value.to_s.delete_prefix(ARRAY_FORMULA_PREFIX).delete_suffix(ARRAY_FORMULA_SUFFIX) << '</f>'
+ str << 't="str">' << '<f t="array" ref="' << cell.r << '">' << cell.clean_value.delete_prefix(ARRAY_FORMULA_PREFIX).delete_suffix(ARRAY_FORMULA_SUFFIX) << '</f>'
str << '<v>' << cell.formula_value.to_s << '</v>' unless cell.formula_value.nil?
end
diff --git a/lib/axlsx/workbook/worksheet/cfvo.rb b/lib/axlsx/workbook/worksheet/cfvo.rb
index 9aeb55ed..71985896 100644
--- a/lib/axlsx/workbook/worksheet/cfvo.rb
+++ b/lib/axlsx/workbook/worksheet/cfvo.rb
@@ -40,10 +40,10 @@ module Axlsx
attr_reader :val
# @see type
- def type=(v); Axlsx::validate_conditional_formatting_value_object_type(v); @type = v end
+ def type=(v); Axlsx.validate_conditional_formatting_value_object_type(v); @type = v end
# @see gte
- def gte=(v); Axlsx::validate_boolean(v); @gte = v end
+ def gte=(v); Axlsx.validate_boolean(v); @gte = v end
# @see val
def val=(v)
diff --git a/lib/axlsx/workbook/worksheet/color_scale.rb b/lib/axlsx/workbook/worksheet/color_scale.rb
index e48de3bb..84ece25b 100644
--- a/lib/axlsx/workbook/worksheet/color_scale.rb
+++ b/lib/axlsx/workbook/worksheet/color_scale.rb
@@ -22,7 +22,7 @@ module Axlsx
# color_scale = Axlsx::ColorScale.two_tone
# @see examples/example.rb conditional formatting examples.
def two_tone
- self.new
+ new
end
# A builder for three tone color gradient
@@ -31,9 +31,9 @@ module Axlsx
# color_scale = Axlsx::ColorScale.three_tone
# @see examples/example.rb conditional formatting examples.
def three_tone
- self.new({ type: :min, val: 0, color: 'FFF8696B' },
- { type: :percent, val: '50', color: 'FFFFEB84' },
- { type: :max, val: 0, color: 'FF63BE7B' })
+ new({ type: :min, val: 0, color: 'FFF8696B' },
+ { type: :percent, val: '50', color: 'FFFFEB84' },
+ { type: :max, val: 0, color: 'FF63BE7B' })
end
end
# A simple typed list of cfvos
diff --git a/lib/axlsx/workbook/worksheet/comment.rb b/lib/axlsx/workbook/worksheet/comment.rb
index 879e6960..4275cf8e 100644
--- a/lib/axlsx/workbook/worksheet/comment.rb
+++ b/lib/axlsx/workbook/worksheet/comment.rb
@@ -80,7 +80,7 @@ module Axlsx
# initialize the vml shape based on this comment's ref/position in the worksheet.
# by default, all columns are 5 columns wide and 5 rows high
def initialize_vml_shape
- pos = Axlsx::name_to_indices(ref)
+ pos = Axlsx.name_to_indices(ref)
@vml_shape = VmlShape.new(row: pos[1], column: pos[0], visible: @visible) do |vml|
vml.left_column = vml.column
vml.right_column = vml.column + 2
diff --git a/lib/axlsx/workbook/worksheet/comments.rb b/lib/axlsx/workbook/worksheet/comments.rb
index cb8efdaa..abf24763 100644
--- a/lib/axlsx/workbook/worksheet/comments.rb
+++ b/lib/axlsx/workbook/worksheet/comments.rb
@@ -20,7 +20,7 @@ module Axlsx
# The part name for this object
# @return [String]
def pn
- "#{COMMENT_PN % (index + 1)}"
+ format(COMMENT_PN, index + 1)
end
# Creates a new Comments object
diff --git a/lib/axlsx/workbook/worksheet/conditional_formatting.rb b/lib/axlsx/workbook/worksheet/conditional_formatting.rb
index 5f8f2474..a8ae3c36 100644
--- a/lib/axlsx/workbook/worksheet/conditional_formatting.rb
+++ b/lib/axlsx/workbook/worksheet/conditional_formatting.rb
@@ -63,7 +63,7 @@ module Axlsx
# @see rules
def rules=(v); @rules = v end
# @see sqref
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
+ def sqref=(v); Axlsx.validate_string(v); @sqref = v end
# Serializes the conditional formatting element
# @example Conditional Formatting XML looks like:
diff --git a/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb b/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb
index 5d626e46..85ef886e 100644
--- a/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb
+++ b/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb
@@ -155,33 +155,33 @@ module Axlsx
end
# @see type
- def type=(v); Axlsx::validate_conditional_formatting_type(v); @type = v end
+ def type=(v); Axlsx.validate_conditional_formatting_type(v); @type = v end
# @see aboveAverage
- def aboveAverage=(v); Axlsx::validate_boolean(v); @aboveAverage = v end
+ def aboveAverage=(v); Axlsx.validate_boolean(v); @aboveAverage = v end
# @see bottom
- def bottom=(v); Axlsx::validate_boolean(v); @bottom = v end
+ def bottom=(v); Axlsx.validate_boolean(v); @bottom = v end
# @see dxfId
- def dxfId=(v); Axlsx::validate_unsigned_numeric(v); @dxfId = v end
+ def dxfId=(v); Axlsx.validate_unsigned_numeric(v); @dxfId = v end
# @see equalAverage
- def equalAverage=(v); Axlsx::validate_boolean(v); @equalAverage = v end
+ def equalAverage=(v); Axlsx.validate_boolean(v); @equalAverage = v end
# @see priority
- def priority=(v); Axlsx::validate_unsigned_numeric(v); @priority = v end
+ def priority=(v); Axlsx.validate_unsigned_numeric(v); @priority = v end
# @see operator
- def operator=(v); Axlsx::validate_conditional_formatting_operator(v); @operator = v end
+ def operator=(v); Axlsx.validate_conditional_formatting_operator(v); @operator = v end
# @see text
- def text=(v); Axlsx::validate_string(v); @text = v end
+ def text=(v); Axlsx.validate_string(v); @text = v end
# @see percent
- def percent=(v); Axlsx::validate_boolean(v); @percent = v end
+ def percent=(v); Axlsx.validate_boolean(v); @percent = v end
# @see rank
- def rank=(v); Axlsx::validate_unsigned_numeric(v); @rank = v end
+ def rank=(v); Axlsx.validate_unsigned_numeric(v); @rank = v end
# @see stdDev
- def stdDev=(v); Axlsx::validate_unsigned_numeric(v); @stdDev = v end
+ def stdDev=(v); Axlsx.validate_unsigned_numeric(v); @stdDev = v end
# @see stopIfTrue
- def stopIfTrue=(v); Axlsx::validate_boolean(v); @stopIfTrue = v end
+ def stopIfTrue=(v); Axlsx.validate_boolean(v); @stopIfTrue = v end
# @see timePeriod
- def timePeriod=(v); Axlsx::validate_time_period_type(v); @timePeriod = v end
+ def timePeriod=(v); Axlsx.validate_time_period_type(v); @timePeriod = v end
# @see formula
- def formula=(v); [*v].each { |x| Axlsx::validate_string(x) }; @formula = [*v].map { |form| ::CGI.escapeHTML(form) } end
+ def formula=(v); [*v].each { |x| Axlsx.validate_string(x) }; @formula = [*v].map { |form| ::CGI.escapeHTML(form) } end
# @see color_scale
def color_scale=(v)
@@ -208,7 +208,7 @@ module Axlsx
str << '<cfRule '
serialized_attributes str
str << '>'
- str << '<formula>' << [*self.formula].join('</formula><formula>') << '</formula>' if @formula
+ str << '<formula>' << [*formula].join('</formula><formula>') << '</formula>' if @formula
@color_scale.to_xml_string(str) if @color_scale && @type == :colorScale
@data_bar.to_xml_string(str) if @data_bar && @type == :dataBar
@icon_set.to_xml_string(str) if @icon_set && @type == :iconSet
diff --git a/lib/axlsx/workbook/worksheet/data_bar.rb b/lib/axlsx/workbook/worksheet/data_bar.rb
index 74158d98..95e54742 100644
--- a/lib/axlsx/workbook/worksheet/data_bar.rb
+++ b/lib/axlsx/workbook/worksheet/data_bar.rb
@@ -100,7 +100,7 @@ module Axlsx
# @param [Color|String] v The color object, or rgb string value to apply
def color=(v)
@color = v if v.is_a? Color
- self.color.rgb = v if v.is_a? String
+ color.rgb = v if v.is_a? String
end
# Serialize this object to an xml string
@@ -109,7 +109,7 @@ module Axlsx
def to_xml_string(str = +'')
serialized_tag('dataBar', str) do
value_objects.to_xml_string(str)
- self.color.to_xml_string(str)
+ color.to_xml_string(str)
end
end
diff --git a/lib/axlsx/workbook/worksheet/data_validation.rb b/lib/axlsx/workbook/worksheet/data_validation.rb
index bc9bc527..a84ab84d 100644
--- a/lib/axlsx/workbook/worksheet/data_validation.rb
+++ b/lib/axlsx/workbook/worksheet/data_validation.rb
@@ -178,57 +178,57 @@ module Axlsx
attr_reader :type
# @see formula1
- def formula1=(v); Axlsx::validate_string(v); @formula1 = v end
+ def formula1=(v); Axlsx.validate_string(v); @formula1 = v end
# @see formula2
- def formula2=(v); Axlsx::validate_string(v); @formula2 = v end
+ def formula2=(v); Axlsx.validate_string(v); @formula2 = v end
# @see allowBlank
- def allowBlank=(v); Axlsx::validate_boolean(v); @allowBlank = v end
+ def allowBlank=(v); Axlsx.validate_boolean(v); @allowBlank = v end
# @see error
- def error=(v); Axlsx::validate_string(v); @error = v end
+ def error=(v); Axlsx.validate_string(v); @error = v end
# @see errorStyle
- def errorStyle=(v); Axlsx::validate_data_validation_error_style(v); @errorStyle = v end
+ def errorStyle=(v); Axlsx.validate_data_validation_error_style(v); @errorStyle = v end
# @see errorTitle
- def errorTitle=(v); Axlsx::validate_string(v); @errorTitle = v end
+ def errorTitle=(v); Axlsx.validate_string(v); @errorTitle = v end
# @see operator
- def operator=(v); Axlsx::validate_data_validation_operator(v); @operator = v end
+ def operator=(v); Axlsx.validate_data_validation_operator(v); @operator = v end
# @see prompt
- def prompt=(v); Axlsx::validate_string(v); @prompt = v end
+ def prompt=(v); Axlsx.validate_string(v); @prompt = v end
# @see promptTitle
- def promptTitle=(v); Axlsx::validate_string(v); @promptTitle = v end
+ def promptTitle=(v); Axlsx.validate_string(v); @promptTitle = v end
# @see showDropDown
def showDropDown=(v)
warn 'The `showDropDown` has an inverted logic, false shows the dropdown list! You should use `hideDropDown` instead.'
- Axlsx::validate_boolean(v)
+ Axlsx.validate_boolean(v)
@showDropDown = v
end
# @see hideDropDown
def hideDropDown=(v)
- Axlsx::validate_boolean(v)
+ Axlsx.validate_boolean(v)
# It's just an alias for the showDropDown attribute, hideDropDown should set the value of the original showDropDown.
@showDropDown = v
end
# @see showErrorMessage
- def showErrorMessage=(v); Axlsx::validate_boolean(v); @showErrorMessage = v end
+ def showErrorMessage=(v); Axlsx.validate_boolean(v); @showErrorMessage = v end
# @see showInputMessage
- def showInputMessage=(v); Axlsx::validate_boolean(v); @showInputMessage = v end
+ def showInputMessage=(v); Axlsx.validate_boolean(v); @showInputMessage = v end
# @see sqref
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
+ def sqref=(v); Axlsx.validate_string(v); @sqref = v end
# @see type
- def type=(v); Axlsx::validate_data_validation_type(v); @type = v end
+ def type=(v); Axlsx.validate_data_validation_type(v); @type = v end
# Serializes the data validation
# @param [String] str
diff --git a/lib/axlsx/workbook/worksheet/date_time_converter.rb b/lib/axlsx/workbook/worksheet/date_time_converter.rb
index e34ef055..01a7c21e 100644
--- a/lib/axlsx/workbook/worksheet/date_time_converter.rb
+++ b/lib/axlsx/workbook/worksheet/date_time_converter.rb
@@ -9,7 +9,7 @@ module Axlsx
# @param [Date] date the date to be serialized
# @return [Numeric]
def self.date_to_serial(date)
- epoch = Axlsx::Workbook::date1904 ? Date.new(1904) : Date.new(1899, 12, 30)
+ epoch = Axlsx::Workbook.date1904 ? Date.new(1904) : Date.new(1899, 12, 30)
offset_date = date.respond_to?(:utc_offset) ? date + date.utc_offset.seconds : date
(offset_date - epoch).to_f
end
@@ -23,7 +23,7 @@ module Axlsx
epoch1900 = -2209161600.0 # Time.utc(1899, 12, 30).to_i
epoch1904 = -2082844800.0 # Time.utc(1904, 1, 1).to_i
seconds_per_day = 86400.0 # 60*60*24
- epoch = Axlsx::Workbook::date1904 ? epoch1904 : epoch1900
+ epoch = Axlsx::Workbook.date1904 ? epoch1904 : epoch1900
(time.utc_offset + time.to_f - epoch) / seconds_per_day
end
end
diff --git a/lib/axlsx/workbook/worksheet/icon_set.rb b/lib/axlsx/workbook/worksheet/icon_set.rb
index 59d67e28..64b0c21a 100644
--- a/lib/axlsx/workbook/worksheet/icon_set.rb
+++ b/lib/axlsx/workbook/worksheet/icon_set.rb
@@ -49,7 +49,7 @@ module Axlsx
attr_reader :showValue
# @see iconSet
- def iconSet=(v); Axlsx::validate_icon_set(v); @iconSet = v end
+ def iconSet=(v); Axlsx.validate_icon_set(v); @iconSet = v end
# @see showValue
def showValue=(v); Axlsx.validate_boolean(v); @showValue = v end
diff --git a/lib/axlsx/workbook/worksheet/merged_cells.rb b/lib/axlsx/workbook/worksheet/merged_cells.rb
index c3fb6dde..90e1bfcb 100644
--- a/lib/axlsx/workbook/worksheet/merged_cells.rb
+++ b/lib/axlsx/workbook/worksheet/merged_cells.rb
@@ -19,7 +19,7 @@ module Axlsx
self << if cells.is_a?(String)
cells
elsif cells.is_a?(Array)
- Axlsx::cell_range(cells, false)
+ Axlsx.cell_range(cells, false)
end
end
diff --git a/lib/axlsx/workbook/worksheet/page_margins.rb b/lib/axlsx/workbook/worksheet/page_margins.rb
index 9c2ddd8e..d0a6f797 100644
--- a/lib/axlsx/workbook/worksheet/page_margins.rb
+++ b/lib/axlsx/workbook/worksheet/page_margins.rb
@@ -78,17 +78,17 @@ module Axlsx
end
# @see left
- def left=(v); Axlsx::validate_unsigned_numeric(v); @left = v end
+ def left=(v); Axlsx.validate_unsigned_numeric(v); @left = v end
# @see right
- def right=(v); Axlsx::validate_unsigned_numeric(v); @right = v end
+ def right=(v); Axlsx.validate_unsigned_numeric(v); @right = v end
# @see top
- def top=(v); Axlsx::validate_unsigned_numeric(v); @top = v end
+ def top=(v); Axlsx.validate_unsigned_numeric(v); @top = v end
# @see bottom
- def bottom=(v); Axlsx::validate_unsigned_numeric(v); @bottom = v end
+ def bottom=(v); Axlsx.validate_unsigned_numeric(v); @bottom = v end
# @see header
- def header=(v); Axlsx::validate_unsigned_numeric(v); @header = v end
+ def header=(v); Axlsx.validate_unsigned_numeric(v); @header = v end
# @see footer
- def footer=(v); Axlsx::validate_unsigned_numeric(v); @footer = v end
+ def footer=(v); Axlsx.validate_unsigned_numeric(v); @footer = v end
# Serializes the page margins element
# @param [String] str
diff --git a/lib/axlsx/workbook/worksheet/page_setup.rb b/lib/axlsx/workbook/worksheet/page_setup.rb
index 6fc8ccba..ddfd698a 100644
--- a/lib/axlsx/workbook/worksheet/page_setup.rb
+++ b/lib/axlsx/workbook/worksheet/page_setup.rb
@@ -198,17 +198,17 @@ module Axlsx
end
# @see fit_to_height
- def fit_to_height=(v); Axlsx::validate_unsigned_int(v); @fit_to_height = v; end
+ def fit_to_height=(v); Axlsx.validate_unsigned_int(v); @fit_to_height = v; end
# @see fit_to_width
- def fit_to_width=(v); Axlsx::validate_unsigned_int(v); @fit_to_width = v; end
+ def fit_to_width=(v); Axlsx.validate_unsigned_int(v); @fit_to_width = v; end
# @see orientation
- def orientation=(v); Axlsx::validate_page_orientation(v); @orientation = v; end
+ def orientation=(v); Axlsx.validate_page_orientation(v); @orientation = v; end
# @see paper_height
- def paper_height=(v); Axlsx::validate_number_with_unit(v); @paper_height = v; end
+ def paper_height=(v); Axlsx.validate_number_with_unit(v); @paper_height = v; end
# @see paper_width
- def paper_width=(v); Axlsx::validate_number_with_unit(v); @paper_width = v; end
+ def paper_width=(v); Axlsx.validate_number_with_unit(v); @paper_width = v; end
# @see scale
- def scale=(v); Axlsx::validate_scale_10_400(v); @scale = v; end
+ def scale=(v); Axlsx.validate_scale_10_400(v); @scale = v; end
# convenience method to achieve sanity when setting fit_to_width and fit_to_height
# as they both default to 1 if only their counterpart is specified.
diff --git a/lib/axlsx/workbook/worksheet/pane.rb b/lib/axlsx/workbook/worksheet/pane.rb
index 6cab87b9..91741e17 100644
--- a/lib/axlsx/workbook/worksheet/pane.rb
+++ b/lib/axlsx/workbook/worksheet/pane.rb
@@ -96,28 +96,28 @@ module Axlsx
# @see active_pane
def active_pane=(v)
- Axlsx::validate_pane_type(v)
- @active_pane = Axlsx::camel(v.to_s, false)
+ Axlsx.validate_pane_type(v)
+ @active_pane = Axlsx.camel(v.to_s, false)
end
# @see state
def state=(v)
- Axlsx::validate_split_state_type(v)
- @state = Axlsx::camel(v.to_s, false)
+ Axlsx.validate_split_state_type(v)
+ @state = Axlsx.camel(v.to_s, false)
end
# @see top_left_cell
def top_left_cell=(v)
cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
- Axlsx::validate_string(cell)
+ Axlsx.validate_string(cell)
@top_left_cell = cell
end
# @see x_split
- def x_split=(v); Axlsx::validate_unsigned_int(v); @x_split = v end
+ def x_split=(v); Axlsx.validate_unsigned_int(v); @x_split = v end
# @see y_split
- def y_split=(v); Axlsx::validate_unsigned_int(v); @y_split = v end
+ def y_split=(v); Axlsx.validate_unsigned_int(v); @y_split = v end
# Serializes the data validation
# @param [String] str
diff --git a/lib/axlsx/workbook/worksheet/pivot_table.rb b/lib/axlsx/workbook/worksheet/pivot_table.rb
index 97c4515b..62349288 100644
--- a/lib/axlsx/workbook/worksheet/pivot_table.rb
+++ b/lib/axlsx/workbook/worksheet/pivot_table.rb
@@ -159,13 +159,13 @@ module Axlsx
# The part name for this table
# @return [String]
def pn
- "#{PIVOT_TABLE_PN % (index + 1)}"
+ format(PIVOT_TABLE_PN, index + 1)
end
# The relationship part name of this pivot table
# @return [String]
def rels_pn
- "#{PIVOT_TABLE_RELS_PN % (index + 1)}"
+ format(PIVOT_TABLE_RELS_PN, index + 1)
end
# The cache_definition for this pivot table
@@ -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 << "/>"
@@ -266,7 +266,7 @@ module Axlsx
# References for header cells
# @return [Array]
def header_cell_refs
- Axlsx::range_to_a(header_range).first
+ Axlsx.range_to_a(header_range).first
end
# The header cells for the pivot table
diff --git a/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb b/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb
index 4928d5ac..3a6053e9 100644
--- a/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb
+++ b/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb
@@ -26,7 +26,7 @@ module Axlsx
# The part name for this table
# @return [String]
def pn
- "#{PIVOT_TABLE_CACHE_DEFINITION_PN % (index + 1)}"
+ format(PIVOT_TABLE_CACHE_DEFINITION_PN, index + 1)
end
# The identifier for this cache
diff --git a/lib/axlsx/workbook/worksheet/protected_ranges.rb b/lib/axlsx/workbook/worksheet/protected_ranges.rb
index b425d053..3e712cb5 100644
--- a/lib/axlsx/workbook/worksheet/protected_ranges.rb
+++ b/lib/axlsx/workbook/worksheet/protected_ranges.rb
@@ -19,7 +19,7 @@ module Axlsx
sqref = if cells.is_a?(String)
cells
elsif cells.is_a?(SimpleTypedList) || cells.is_a?(Array)
- Axlsx::cell_range(cells, false)
+ Axlsx.cell_range(cells, false)
end
self << ProtectedRange.new(sqref: sqref, name: "Range#{size}")
last
diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb
index 9f66959a..b2cd8a51 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
@@ -199,7 +199,7 @@ module Axlsx
return unless INLINE_STYLES.include?(attr.to_sym)
Axlsx.send(validator, value) unless validator.nil?
- self.instance_variable_set :"@#{attr}", value
+ instance_variable_set :"@#{attr}", value
end
# Serializes the RichTextRun
@@ -208,7 +208,7 @@ module Axlsx
def to_xml_string(str = +'')
valid = RichTextRun::INLINE_STYLES
data = Axlsx.instance_values_for(self).transform_keys(&:to_sym)
- data = data.select { |key, value| valid.include?(key) && !value.nil? }
+ data = data.select { |key, value| !value.nil? && valid.include?(key) }
str << '<r><rPr>'
data.each do |key, val|
@@ -221,7 +221,7 @@ module Axlsx
str << '<' << key.to_s << ' val="' << xml_value(val) << '"/>'
end
end
- clean_value = Axlsx::trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@value.to_s))
+ clean_value = Axlsx.trust_input ? @value.to_s : ::CGI.escapeHTML(Axlsx.sanitize(@value.to_s))
str << '</rPr><t>' << clean_value << '</t></r>'
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/row.rb b/lib/axlsx/workbook/worksheet/row.rb
index 0b25fc59..86d38616 100644
--- a/lib/axlsx/workbook/worksheet/row.rb
+++ b/lib/axlsx/workbook/worksheet/row.rb
@@ -129,7 +129,7 @@ module Axlsx
# @see height
def height=(v)
unless v.nil?
- Axlsx::validate_unsigned_numeric(v)
+ Axlsx.validate_unsigned_numeric(v)
@custom_height = true
@ht = v
end
diff --git a/lib/axlsx/workbook/worksheet/row_breaks.rb b/lib/axlsx/workbook/worksheet/row_breaks.rb
index 381dc0b6..98409ab4 100644
--- a/lib/axlsx/workbook/worksheet/row_breaks.rb
+++ b/lib/axlsx/workbook/worksheet/row_breaks.rb
@@ -26,7 +26,7 @@ module Axlsx
def to_xml_string(str = +'')
return if empty?
- str << '<rowBreaks count="' << self.size.to_s << '" manualBreakCount="' << self.size.to_s << '">'
+ str << '<rowBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">'
each { |brk| brk.to_xml_string(str) }
str << '</rowBreaks>'
end
diff --git a/lib/axlsx/workbook/worksheet/selection.rb b/lib/axlsx/workbook/worksheet/selection.rb
index 1a2633b4..3eaefeec 100644
--- a/lib/axlsx/workbook/worksheet/selection.rb
+++ b/lib/axlsx/workbook/worksheet/selection.rb
@@ -75,21 +75,21 @@ module Axlsx
# @see active_cell
def active_cell=(v)
cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
- Axlsx::validate_string(cell)
+ Axlsx.validate_string(cell)
@active_cell = cell
end
# @see active_cell_id
- def active_cell_id=(v); Axlsx::validate_unsigned_int(v); @active_cell_id = v end
+ def active_cell_id=(v); Axlsx.validate_unsigned_int(v); @active_cell_id = v end
# @see pane
def pane=(v)
- Axlsx::validate_pane_type(v)
- @pane = Axlsx::camel(v, false)
+ Axlsx.validate_pane_type(v)
+ @pane = Axlsx.camel(v, false)
end
# @see sqref
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
+ def sqref=(v); Axlsx.validate_string(v); @sqref = v end
# Serializes the data validation
# @param [String] str
diff --git a/lib/axlsx/workbook/worksheet/sheet_protection.rb b/lib/axlsx/workbook/worksheet/sheet_protection.rb
index ce39b1b4..abf5e452 100644
--- a/lib/axlsx/workbook/worksheet/sheet_protection.rb
+++ b/lib/axlsx/workbook/worksheet/sheet_protection.rb
@@ -87,25 +87,25 @@ module Axlsx
encoded_password = encode_password(password)
password_as_hex = [encoded_password].pack("v")
- password_as_string = password_as_hex.unpack("H*").first.upcase
+ password_as_string = password_as_hex.unpack1("H*").upcase
password_as_string[2..3] + password_as_string[0..1]
end
# Encodes a given password
# Based on the algorithm provided by Daniel Rentz of OpenOffice.
- # http://www.openoffice.org/sc/excelfileformat.pdf, Revision 1.42, page 115 (21.05.2012)
+ # https://www.openoffice.org/sc/excelfileformat.pdf, Revision 1.42, page 115 (21.05.2012)
# @return [String]
def encode_password(password)
i = 0
- chars = password.split("")
+ chars = password.chars
count = chars.size
chars.collect! do |char|
i += 1
- char = char.unpack('c')[0] << i # ord << i
+ char = char.unpack1('c') << i # ord << i
low_15 = char & 0x7fff
- high_15 = char & 0x7fff << 15
+ high_15 = char & (0x7fff << 15)
high_15 = high_15 >> 15
low_15 | high_15
end
diff --git a/lib/axlsx/workbook/worksheet/sheet_view.rb b/lib/axlsx/workbook/worksheet/sheet_view.rb
index ee19061a..1ecfc7ab 100644
--- a/lib/axlsx/workbook/worksheet/sheet_view.rb
+++ b/lib/axlsx/workbook/worksheet/sheet_view.rb
@@ -162,32 +162,32 @@ module Axlsx
end
# @see color_id
- def color_id=(v); Axlsx::validate_unsigned_int(v); @color_id = v end
+ def color_id=(v); Axlsx.validate_unsigned_int(v); @color_id = v end
# @see top_left_cell
def top_left_cell=(v)
cell = (v.instance_of?(Axlsx::Cell) ? v.r_abs : v)
- Axlsx::validate_string(cell)
+ Axlsx.validate_string(cell)
@top_left_cell = cell
end
# @see view
- def view=(v); Axlsx::validate_sheet_view_type(v); @view = v end
+ def view=(v); Axlsx.validate_sheet_view_type(v); @view = v end
# @see workbook_view_id
- def workbook_view_id=(v); Axlsx::validate_unsigned_int(v); @workbook_view_id = v end
+ def workbook_view_id=(v); Axlsx.validate_unsigned_int(v); @workbook_view_id = v end
# @see zoom_scale
- def zoom_scale=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale = v end
+ def zoom_scale=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale = v end
# @see zoom_scale_normal
- def zoom_scale_normal=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_normal = v end
+ def zoom_scale_normal=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale_normal = v end
# @see zoom_scale_page_layout_view
- def zoom_scale_page_layout_view=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_page_layout_view = v end
+ def zoom_scale_page_layout_view=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale_page_layout_view = v end
# @see zoom_scale_sheet_layout_view
- def zoom_scale_sheet_layout_view=(v); Axlsx::validate_scale_0_10_400(v); @zoom_scale_sheet_layout_view = v end
+ def zoom_scale_sheet_layout_view=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale_sheet_layout_view = v end
# Serializes the data validation
# @param [String] str
diff --git a/lib/axlsx/workbook/worksheet/table.rb b/lib/axlsx/workbook/worksheet/table.rb
index 210833e0..2bfb64eb 100644
--- a/lib/axlsx/workbook/worksheet/table.rb
+++ b/lib/axlsx/workbook/worksheet/table.rb
@@ -44,7 +44,7 @@ module Axlsx
# The part name for this table
# @return [String]
def pn
- "#{TABLE_PN % (index + 1)}"
+ format(TABLE_PN, index + 1)
end
# The relationship id for this table.
diff --git a/lib/axlsx/workbook/worksheet/table_style_info.rb b/lib/axlsx/workbook/worksheet/table_style_info.rb
index 3793d488..218e313e 100644
--- a/lib/axlsx/workbook/worksheet/table_style_info.rb
+++ b/lib/axlsx/workbook/worksheet/table_style_info.rb
@@ -34,7 +34,7 @@ module Axlsx
# explicitly be disabled or all will show.
def initialize_defaults
%w(show_first_column show_last_column show_row_stripes show_column_stripes).each do |attr|
- self.send("#{attr}=", 0)
+ send("#{attr}=", 0)
end
end
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 90461c66..081f50d8 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -327,7 +327,7 @@ module Axlsx
# @param [String] name
def name=(name)
validate_sheet_name name
- @name = Axlsx::coder.encode(name)
+ @name = Axlsx.coder.encode(name)
end
# The auto filter range for the worksheet
@@ -345,13 +345,13 @@ module Axlsx
# The part name of this worksheet
# @return [String]
def pn
- "#{WORKSHEET_PN % (index + 1)}"
+ format(WORKSHEET_PN, index + 1)
end
# The relationship part name of this worksheet
# @return [String]
def rels_pn
- "#{WORKSHEET_RELS_PN % (index + 1)}"
+ format(WORKSHEET_RELS_PN, index + 1)
end
# The relationship id of this worksheet.
@@ -547,7 +547,7 @@ module Axlsx
widths.each_with_index do |value, index|
next if value.nil?
- Axlsx::validate_unsigned_numeric(value) unless value.nil?
+ Axlsx.validate_unsigned_numeric(value) unless value.nil?
find_or_create_column_info(index).width = value
end
end
@@ -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
@@ -673,11 +673,11 @@ module Axlsx
parts.first
else
if parts.size > 2
- raise ArgumentError, (ERR_CELL_REFERENCE_INVALID % cell_def)
+ raise ArgumentError, format(ERR_CELL_REFERENCE_INVALID, cell_def)
elsif parts.first.nil?
- raise ArgumentError, (ERR_CELL_REFERENCE_MISSING_CELL % [cell_def.split(":").first, cell_def])
+ raise ArgumentError, format(ERR_CELL_REFERENCE_MISSING_CELL, cell_def.split(":").first, cell_def)
elsif parts.last.nil?
- raise ArgumentError, (ERR_CELL_REFERENCE_MISSING_CELL % [cell_def.split(":").last, cell_def])
+ raise ArgumentError, format(ERR_CELL_REFERENCE_MISSING_CELL, cell_def.split(":").last, cell_def)
end
range(*parts)
@@ -688,7 +688,7 @@ module Axlsx
# @param [String] name The cell or cell range to return. "A1" will return the first cell of the first row.
# @return [Cell]
def name_to_cell(name)
- col_index, row_index = *Axlsx::name_to_indices(name)
+ col_index, row_index = *Axlsx.name_to_indices(name)
r = rows[row_index]
@@ -711,7 +711,7 @@ module Axlsx
# @note The XLSX format does not support worksheet-specific styles. Even when using this method
# you're still working with the single global {Axlsx::Styles} object in the workbook.
def styles
- @styles ||= self.workbook.styles
+ @styles ||= workbook.styles
end
# shortcut level to specify the outline level for a series of rows
@@ -753,15 +753,15 @@ 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
- raise ArgumentError, (ERR_SHEET_NAME_CHARACTER_FORBIDDEN % name) if WORKSHEET_NAME_FORBIDDEN_CHARS.any? { |char| name.include? char }
+ raise ArgumentError, format(ERR_SHEET_NAME_TOO_LONG, name) if character_length > WORKSHEET_MAX_NAME_LENGTH
+ raise ArgumentError, format(ERR_SHEET_NAME_CHARACTER_FORBIDDEN, name) if WORKSHEET_NAME_FORBIDDEN_CHARS.any? { |char| name.include? char }
- name = Axlsx::coder.encode(name)
+ name = Axlsx.coder.encode(name)
sheet_names = @workbook.worksheets.reject { |s| s == self }.map(&:name)
- raise ArgumentError, (ERR_DUPLICATE_SHEET_NAME % name) if sheet_names.include?(name)
+ raise ArgumentError, format(ERR_DUPLICATE_SHEET_NAME, name) if sheet_names.include?(name)
end
def serializable_parts
@@ -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
diff --git a/lib/axlsx/workbook/worksheet/worksheet_comments.rb b/lib/axlsx/workbook/worksheet/worksheet_comments.rb
index c5f5ad13..3ebaedee 100644
--- a/lib/axlsx/workbook/worksheet/worksheet_comments.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet_comments.rb
@@ -37,7 +37,7 @@ module Axlsx
# Helper method to tell us if there are comments in the comments collection
# @return [Boolean]
- def has_comments?
+ def has_comments? # rubocop:disable Naming/PredicateName
!comments.empty?
end
diff --git a/lib/axlsx/workbook/worksheet/worksheet_drawing.rb b/lib/axlsx/workbook/worksheet/worksheet_drawing.rb
index 18c7189a..6488655c 100644
--- a/lib/axlsx/workbook/worksheet/worksheet_drawing.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet_drawing.rb
@@ -15,8 +15,12 @@ module Axlsx
@drawing = nil
end
+ # The worksheet that owns the drawing
+ # @return [Worksheet]
attr_reader :worksheet
+ # The drawing object
+ # @return [Drawing]
attr_reader :drawing
# adds a chart to the drawing object
@@ -38,7 +42,7 @@ module Axlsx
# helper method to tell us if the drawing has something in it or not
# @return [Boolean]
- def has_drawing?
+ def has_drawing? # rubocop:disable Naming/PredicateName
@drawing.is_a? Drawing
end
diff --git a/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb b/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb
index 80f7ba09..2195fc6b 100644
--- a/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb
@@ -41,7 +41,7 @@ module Axlsx
# @param [String|Cell] cell_reference The string reference or cell that defines where this hyperlink shows in the worksheet.
def ref=(cell_reference)
cell_reference = cell_reference.r if cell_reference.is_a?(Cell)
- Axlsx::validate_string cell_reference
+ Axlsx.validate_string cell_reference
@ref = cell_reference
end
@@ -69,7 +69,7 @@ module Axlsx
# r:id should only be specified for external targets.
# @return [Hash]
def location_or_id
- @target == :external ? { "r:id": relationship.Id } : { location: Axlsx::coder.encode(location) }
+ @target == :external ? { "r:id": relationship.Id } : { location: Axlsx.coder.encode(location) }
end
end
end
diff --git a/test/content_type/tc_content_type.rb b/test/content_type/tc_content_type.rb
index a3c6603f..2108c1fe 100644
--- a/test/content_type/tc_content_type.rb
+++ b/test/content_type/tc_content_type.rb
@@ -21,30 +21,30 @@ class TestContentType < Test::Unit::TestCase
# default
assert_equal(2, @doc.xpath("//xmlns:Default").size, "There should be 2 default types")
- node = @doc.xpath(d_path % Axlsx::XML_CT).first
+ node = @doc.xpath(format(d_path, Axlsx::XML_CT)).first
assert_equal(node["Extension"], Axlsx::XML_EX.to_s, "xml content type invalid")
- node = @doc.xpath(d_path % Axlsx::RELS_CT).first
+ node = @doc.xpath(format(d_path, Axlsx::RELS_CT)).first
assert_equal(node["Extension"], Axlsx::RELS_EX.to_s, "relationships content type invalid")
# overrride
assert_equal(4, @doc.xpath("//xmlns:Override").size, "There should be 4 Override types")
- node = @doc.xpath(o_path % Axlsx::APP_CT).first
+ node = @doc.xpath(format(o_path, Axlsx::APP_CT)).first
assert_equal(node["PartName"], "/#{Axlsx::APP_PN}", "App part name invalid")
- node = @doc.xpath(o_path % Axlsx::CORE_CT).first
+ node = @doc.xpath(format(o_path, Axlsx::CORE_CT)).first
assert_equal(node["PartName"], "/#{Axlsx::CORE_PN}", "Core part name invalid")
- node = @doc.xpath(o_path % Axlsx::STYLES_CT).first
+ node = @doc.xpath(format(o_path, Axlsx::STYLES_CT)).first
assert_equal(node["PartName"], "/xl/#{Axlsx::STYLES_PN}", "Styles part name invalid")
- node = @doc.xpath(o_path % Axlsx::WORKBOOK_CT).first
+ node = @doc.xpath(format(o_path, Axlsx::WORKBOOK_CT)).first
assert_equal(node["PartName"], "/#{Axlsx::WORKBOOK_PN}", "Workbook part invalid")
end
@@ -56,13 +56,13 @@ class TestContentType < Test::Unit::TestCase
doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
assert_equal(5, doc.xpath("//xmlns:Override").size, "adding a worksheet should add another type")
- assert_equal(doc.xpath(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
+ assert_equal(doc.xpath(format(o_path, Axlsx::WORKSHEET_CT)).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
ws = @package.workbook.add_worksheet
doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
assert_equal(6, doc.xpath("//xmlns:Override").size, "adding workship should add another type")
- assert_equal(doc.xpath(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
+ assert_equal(doc.xpath(format(o_path, Axlsx::WORKSHEET_CT)).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
end
def test_drawings_and_charts_need_content_types
@@ -73,13 +73,13 @@ class TestContentType < Test::Unit::TestCase
doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
assert_equal(7, doc.xpath("//xmlns:Override").size, "expected 7 types got #{doc.css('Types Override').size}")
- assert_equal(doc.xpath(o_path % Axlsx::DRAWING_CT).first["PartName"], "/xl/#{ws.drawing.pn}", "Drawing part name invlid")
- assert_equal(doc.xpath(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
+ assert_equal(doc.xpath(format(o_path, Axlsx::DRAWING_CT)).first["PartName"], "/xl/#{ws.drawing.pn}", "Drawing part name invlid")
+ assert_equal(doc.xpath(format(o_path, Axlsx::CHART_CT)).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
c = ws.add_chart Axlsx::Pie3DChart
doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
assert_equal(8, doc.xpath("//xmlns:Override").size, "expected 7 types got #{doc.css('Types Override').size}")
- assert_equal(doc.xpath(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
+ assert_equal(doc.xpath(format(o_path, Axlsx::CHART_CT)).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
end
end
diff --git a/test/drawing/tc_d_lbls.rb b/test/drawing/tc_d_lbls.rb
index 9bb2d4ba..c3172326 100644
--- a/test/drawing/tc_d_lbls.rb
+++ b/test/drawing/tc_d_lbls.rb
@@ -53,7 +53,7 @@ class TestDLbls < Test::Unit::TestCase
doc = Nokogiri::XML(str)
Axlsx.instance_values_for(@d_lbls).each do |name, value|
- assert(doc.xpath("//c:#{Axlsx::camel(name, false)}[@val='#{value}']"), "#{name} is properly serialized")
+ assert(doc.xpath("//c:#{Axlsx.camel(name, false)}[@val='#{value}']"), "#{name} is properly serialized")
end
end
end
diff --git a/test/drawing/tc_vml_drawing.rb b/test/drawing/tc_vml_drawing.rb
index fa939f56..e089457e 100644
--- a/test/drawing/tc_vml_drawing.rb
+++ b/test/drawing/tc_vml_drawing.rb
@@ -16,6 +16,12 @@ class TestVmlDrawing < Test::Unit::TestCase
assert_raise(ArgumentError) { Axlsx::VmlDrawing.new }
end
+ def test_pn
+ str = @vml_drawing.pn
+
+ assert_equal("drawings/vmlDrawing1.vml", str)
+ end
+
def test_to_xml_string
str = @vml_drawing.to_xml_string
doc = Nokogiri::XML(str)
diff --git a/test/tc_axlsx.rb b/test/tc_axlsx.rb
index f4f6a01d..25b21777 100644
--- a/test/tc_axlsx.rb
+++ b/test/tc_axlsx.rb
@@ -96,9 +96,9 @@ class TestAxlsx < Test::Unit::TestCase
end
def test_range_to_a
- assert_equal([['A1', 'B1', 'C1']], Axlsx::range_to_a('A1:C1'))
- assert_equal([['A1', 'B1', 'C1'], ['A2', 'B2', 'C2']], Axlsx::range_to_a('A1:C2'))
- assert_equal([['Z5', 'AA5', 'AB5'], ['Z6', 'AA6', 'AB6']], Axlsx::range_to_a('Z5:AB6'))
+ assert_equal([['A1', 'B1', 'C1']], Axlsx.range_to_a('A1:C1'))
+ assert_equal([['A1', 'B1', 'C1'], ['A2', 'B2', 'C2']], Axlsx.range_to_a('A1:C2'))
+ assert_equal([['Z5', 'AA5', 'AB5'], ['Z6', 'AA6', 'AB6']], Axlsx.range_to_a('Z5:AB6'))
end
def test_sanitize_frozen_control_strippped
@@ -165,15 +165,15 @@ class TestAxlsx < Test::Unit::TestCase
def test_escape_formulas
Axlsx.instance_variable_set(:@escape_formulas, nil)
- refute Axlsx::escape_formulas
+ assert Axlsx.escape_formulas
- Axlsx::escape_formulas = true
+ Axlsx.escape_formulas = true
- assert Axlsx::escape_formulas
+ assert Axlsx.escape_formulas
- Axlsx::escape_formulas = false
+ Axlsx.escape_formulas = false
- refute Axlsx::escape_formulas
+ refute Axlsx.escape_formulas
ensure
Axlsx.instance_variable_set(:@escape_formulas, nil)
end
diff --git a/test/tc_package.rb b/test/tc_package.rb
index 75fe2cdf..9b057a94 100644
--- a/test/tc_package.rb
+++ b/test/tc_package.rb
@@ -319,8 +319,8 @@ class TestPackage < Test::Unit::TestCase
end
def test_name_to_indices
- assert_equal([0, 0], Axlsx::name_to_indices('A1'))
- assert_equal([0, 99], Axlsx::name_to_indices('A100'), 'needs to axcept rows that contain 0')
+ assert_equal([0, 0], Axlsx.name_to_indices('A1'))
+ assert_equal([0, 99], Axlsx.name_to_indices('A100'), 'needs to axcept rows that contain 0')
end
def test_to_stream
diff --git a/test/util/tc_mime_type_utils.rb b/test/util/tc_mime_type_utils.rb
index 16ba45cd..f990e8e2 100644
--- a/test/util/tc_mime_type_utils.rb
+++ b/test/util/tc_mime_type_utils.rb
@@ -14,11 +14,11 @@ class TestMimeTypeUtils < Test::Unit::TestCase
def teardown; end
def test_mime_type_utils
- assert_equal('image/jpeg', Axlsx::MimeTypeUtils::get_mime_type(@test_img))
- assert_equal('image/png', Axlsx::MimeTypeUtils::get_mime_type_from_uri(@test_img_url))
+ assert_equal('image/jpeg', Axlsx::MimeTypeUtils.get_mime_type(@test_img))
+ assert_equal('image/png', Axlsx::MimeTypeUtils.get_mime_type_from_uri(@test_img_url))
end
def test_escape_uri
- assert_raise(URI::InvalidURIError) { Axlsx::MimeTypeUtils::get_mime_type_from_uri('| ls') }
+ assert_raise(URI::InvalidURIError) { Axlsx::MimeTypeUtils.get_mime_type_from_uri('| ls') }
end
end
diff --git a/test/workbook/tc_workbook.rb b/test/workbook/tc_workbook.rb
index 51fe3976..2422cc79 100644
--- a/test/workbook/tc_workbook.rb
+++ b/test/workbook/tc_workbook.rb
@@ -185,7 +185,7 @@ class TestWorkbook < Test::Unit::TestCase
end
def test_escape_formulas
- Axlsx::escape_formulas = false
+ Axlsx.escape_formulas = false
p = Axlsx::Package.new
@wb = p.workbook
@@ -194,7 +194,7 @@ class TestWorkbook < Test::Unit::TestCase
assert_false @wb.add_worksheet(escape_formulas: false).escape_formulas
assert @wb.add_worksheet(escape_formulas: true).escape_formulas
- Axlsx::escape_formulas = true
+ Axlsx.escape_formulas = true
p = Axlsx::Package.new
@wb = p.workbook
diff --git a/test/workbook/worksheet/auto_filter/tc_sort_condition.rb b/test/workbook/worksheet/auto_filter/tc_sort_condition.rb
new file mode 100644
index 00000000..67e4bdac
--- /dev/null
+++ b/test/workbook/worksheet/auto_filter/tc_sort_condition.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+require 'tc_helper'
+
+class TestSortCondition < Test::Unit::TestCase
+ def setup
+ ws = Axlsx::Package.new.workbook.add_worksheet
+ ws.add_row ['first', 'second', 'third']
+ 3.times { |index| ws.add_row [1 * index, 2 * index, 3 * index] }
+ ws.auto_filter = 'A1:C4'
+ @auto_filter = ws.auto_filter
+ @auto_filter.sort_state.add_sort_condition(column_index: 0)
+ @auto_filter.sort_state.add_sort_condition(column_index: 1, order: :desc)
+ @auto_filter.sort_state.add_sort_condition(column_index: 2, custom_list: ['low', 'middle', 'high'])
+ @sort_state = @auto_filter.sort_state
+ @sort_conditions = @sort_state.sort_conditions
+ end
+
+ def test_ref_to_single_column
+ assert_equal('A2:A4', @sort_conditions[0].ref_to_single_column('A2:C4', 0))
+ end
+
+ def test_to_xml_string
+ doc = Nokogiri::XML(@sort_state.to_xml_string)
+
+ assert_equal(3, doc.xpath("sortState//sortCondition").size)
+ assert_equal('A2:A4', doc.xpath("sortState//sortCondition")[0].attribute('ref').value)
+ assert_nil doc.xpath("sortState//sortCondition")[0].attribute('descending')
+ assert_nil doc.xpath("sortState//sortCondition")[0].attribute('customList')
+ assert_equal('1', doc.xpath("sortState//sortCondition")[1].attribute('descending').value)
+ assert_equal('B2:B4', doc.xpath("sortState//sortCondition")[1].attribute('ref').value)
+ assert_nil doc.xpath("sortState//sortCondition")[1].attribute('customList')
+ assert_equal('C2:C4', doc.xpath("sortState//sortCondition")[2].attribute('ref').value)
+ assert_equal('low,middle,high', doc.xpath("sortState//sortCondition")[2].attribute('customList').value)
+ assert_nil doc.xpath("sortState//sortCondition")[2].attribute('descending')
+ end
+end
diff --git a/test/workbook/worksheet/auto_filter/tc_sort_state.rb b/test/workbook/worksheet/auto_filter/tc_sort_state.rb
new file mode 100644
index 00000000..db3d03c0
--- /dev/null
+++ b/test/workbook/worksheet/auto_filter/tc_sort_state.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+require 'tc_helper'
+
+class TestSortState < Test::Unit::TestCase
+ def setup
+ ws = Axlsx::Package.new.workbook.add_worksheet
+ ws.add_row ['first', 'second', 'third']
+ 3.times { |index| ws.add_row [1 * index, 2 * index, 3 * index] }
+ ws.auto_filter = 'A1:C4'
+ @auto_filter = ws.auto_filter
+ @auto_filter.sort_state.add_sort_condition(column_index: 0)
+ @sort_state = @auto_filter.sort_state
+ end
+
+ def test_sort_conditions
+ assert @sort_state.sort_conditions.is_a?(Axlsx::SimpleTypedList)
+ assert_equal @sort_state.sort_conditions.allowed_types, [Axlsx::SortCondition]
+ end
+
+ def test_add_sort_conditions
+ @sort_state.add_sort_condition(column_index: 0) do |condition|
+ assert condition.is_a? SortCondition
+ end
+ end
+
+ def test_increment_cell_value
+ assert_equal('A2', @sort_state.increment_cell_value('A1'))
+ end
+
+ def test_to_xml_string
+ doc = Nokogiri::XML(@sort_state.to_xml_string)
+
+ assert_equal('A2:C4', doc.xpath("sortState")[0].attribute('ref').value)
+ end
+end
diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb
index a8ab6ca1..94c424b3 100644
--- a/test/workbook/worksheet/tc_cell.rb
+++ b/test/workbook/worksheet/tc_cell.rb
@@ -411,7 +411,7 @@ class TestCell < Test::Unit::TestCase
def test_to_xml_string_formula
p = Axlsx::Package.new
- ws = p.workbook.add_worksheet do |sheet|
+ ws = p.workbook.add_worksheet(escape_formulas: false) do |sheet|
sheet.add_row ["=IF(2+2=4,4,5)"]
end
doc = Nokogiri::XML(ws.to_xml_string)
@@ -512,7 +512,7 @@ class TestCell < Test::Unit::TestCase
def test_to_xml_string_array_formula
p = Axlsx::Package.new
- ws = p.workbook.add_worksheet do |sheet|
+ ws = p.workbook.add_worksheet(escape_formulas: false) do |sheet|
sheet.add_row ["{=SUM(C2:C11*D2:D11)}"]
end
doc = Nokogiri::XML(ws.to_xml_string)
diff --git a/test/workbook/worksheet/tc_comment.rb b/test/workbook/worksheet/tc_comment.rb
index aa33dba4..80bd01cb 100644
--- a/test/workbook/worksheet/tc_comment.rb
+++ b/test/workbook/worksheet/tc_comment.rb
@@ -41,7 +41,7 @@ class TestComment < Test::Unit::TestCase
end
def test_vml_shape
- pos = Axlsx::name_to_indices(@c1.ref)
+ pos = Axlsx.name_to_indices(@c1.ref)
assert(@c1.vml_shape.is_a?(Axlsx::VmlShape))
assert_equal(@c1.vml_shape.column, pos[0])
diff --git a/test/workbook/worksheet/tc_comments.rb b/test/workbook/worksheet/tc_comments.rb
index d9be807e..b3de3acd 100644
--- a/test/workbook/worksheet/tc_comments.rb
+++ b/test/workbook/worksheet/tc_comments.rb
@@ -37,7 +37,7 @@ class TestComments < Test::Unit::TestCase
end
def test_pn
- assert_equal(@ws.comments.pn, Axlsx::COMMENT_PN % (@ws.index + 1).to_s)
+ assert_equal(@ws.comments.pn, format(Axlsx::COMMENT_PN, @ws.index + 1))
end
def test_index
diff --git a/test/workbook/worksheet/tc_date_time_converter.rb b/test/workbook/worksheet/tc_date_time_converter.rb
index 5cc9d619..6d95b111 100644
--- a/test/workbook/worksheet/tc_date_time_converter.rb
+++ b/test/workbook/worksheet/tc_date_time_converter.rb
@@ -16,7 +16,7 @@ class TestDateTimeConverter < Test::Unit::TestCase
"2006-02-01" => 38_749.0,
"9999-12-31" => 2_958_465.0
}.each do |date_string, expected|
- serial = Axlsx::DateTimeConverter::date_to_serial Date.parse(date_string)
+ serial = Axlsx::DateTimeConverter.date_to_serial Date.parse(date_string)
assert_equal expected, serial
end
@@ -31,7 +31,7 @@ class TestDateTimeConverter < Test::Unit::TestCase
"2006-02-01" => 37_287.0,
"9999-12-31" => 2_957_003.0
}.each do |date_string, expected|
- serial = Axlsx::DateTimeConverter::date_to_serial Date.parse(date_string)
+ serial = Axlsx::DateTimeConverter.date_to_serial Date.parse(date_string)
assert_equal expected, serial
end
@@ -46,7 +46,7 @@ class TestDateTimeConverter < Test::Unit::TestCase
"1900-01-01T12:00:00Z" => 2.5, # wrongly indicated as 1.5 in the spec!
"9999-12-31T23:59:59Z" => 2_958_465.9999884
}.each do |time_string, expected|
- serial = Axlsx::DateTimeConverter::time_to_serial Time.parse(time_string)
+ serial = Axlsx::DateTimeConverter.time_to_serial Time.parse(time_string)
assert_in_delta expected, serial, @margin_of_error
end
@@ -61,7 +61,7 @@ class TestDateTimeConverter < Test::Unit::TestCase
"1904-01-01T12:00:00Z" => 0.5000000,
"9999-12-31T23:59:59Z" => 2_957_003.9999884
}.each do |time_string, expected|
- serial = Axlsx::DateTimeConverter::time_to_serial Time.parse(time_string)
+ serial = Axlsx::DateTimeConverter.time_to_serial Time.parse(time_string)
assert_in_delta expected, serial, @margin_of_error
end
@@ -72,9 +72,9 @@ class TestDateTimeConverter < Test::Unit::TestCase
local = Time.parse "2012-01-01 09:00:00 +0900"
assert_equal local, utc
- assert_equal Axlsx::DateTimeConverter::time_to_serial(local) - (local.utc_offset.to_f / 86_400), Axlsx::DateTimeConverter::time_to_serial(utc)
+ assert_equal Axlsx::DateTimeConverter.time_to_serial(local) - (local.utc_offset.to_f / 86_400), Axlsx::DateTimeConverter.time_to_serial(utc)
Axlsx::Workbook.date1904 = true
- assert_equal Axlsx::DateTimeConverter::time_to_serial(local) - (local.utc_offset.to_f / 86_400), Axlsx::DateTimeConverter::time_to_serial(utc)
+ assert_equal Axlsx::DateTimeConverter.time_to_serial(local) - (local.utc_offset.to_f / 86_400), Axlsx::DateTimeConverter.time_to_serial(utc)
end
end
diff --git a/test/workbook/worksheet/tc_pivot_table.rb b/test/workbook/worksheet/tc_pivot_table.rb
index 606982db..d4db9cef 100644
--- a/test/workbook/worksheet/tc_pivot_table.rb
+++ b/test/workbook/worksheet/tc_pivot_table.rb
@@ -144,6 +144,12 @@ class TestPivotTable < Test::Unit::TestCase
assert_equal(2, @ws.relationships.size, "adding a pivot table adds a relationship")
end
+ def test_rels_pn
+ @ws.add_pivot_table('G5:G6', 'A1:D5')
+
+ assert_equal("pivotTables/_rels/pivotTable1.xml.rels", @ws.pivot_tables.first.rels_pn)
+ end
+
def test_to_xml_string
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5', { no_subtotals_on_headers: ['Year'] }) do |pt|
pt.rows = ['Year', 'Month']
diff --git a/test/workbook/worksheet/tc_sheet_protection.rb b/test/workbook/worksheet/tc_sheet_protection.rb
index ebfff4b6..11a43ac8 100644
--- a/test/workbook/worksheet/tc_sheet_protection.rb
+++ b/test/workbook/worksheet/tc_sheet_protection.rb
@@ -57,7 +57,7 @@ class TestSheetProtection < Test::Unit::TestCase
doc = Nokogiri::XML(@sp.to_xml_string)
@options.each do |key, value|
- assert(doc.xpath("//sheetProtection[@#{key.to_s.gsub(/_(.)/) { $1.upcase }}='#{value}']"))
+ assert(doc.xpath("//sheetProtection[@#{key.to_s.gsub(/_(.)/) { ::Regexp.last_match(1).upcase }}='#{value}']"))
end
end
end
diff --git a/test/workbook/worksheet/tc_table_style_info.rb b/test/workbook/worksheet/tc_table_style_info.rb
index 6cb12b94..2e327a73 100644
--- a/test/workbook/worksheet/tc_table_style_info.rb
+++ b/test/workbook/worksheet/tc_table_style_info.rb
@@ -9,7 +9,7 @@ class TestTableStyleInfo < Test::Unit::TestCase
40.times do
@ws.add_row %w(aa bb cc dd ee ff gg hh ii jj kk)
end
- @table = @ws.add_table(Axlsx::cell_range([@ws.rows.first.cells.first, @ws.rows.last.cells.last], false), name: 'foo')
+ @table = @ws.add_table(Axlsx.cell_range([@ws.rows.first.cells.first, @ws.rows.last.cells.last], false), name: 'foo')
@options = { show_first_column: 1,
show_last_column: 1,
show_row_stripes: 1,
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index 4ec74efb..464d2e64 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -456,14 +456,14 @@ class TestWorksheet < Test::Unit::TestCase
end
def test_to_xml_string_with_illegal_chars
- old = Axlsx::trust_input
- Axlsx::trust_input = false
+ old = Axlsx.trust_input
+ Axlsx.trust_input = false
nasties = "\v\u2028\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u001f"
@ws.add_row [nasties]
assert_equal(0, @ws.rows.last.cells.last.value.index("\v"))
assert_nil(@ws.to_xml_string.index("\v"))
- Axlsx::trust_input = old
+ Axlsx.trust_input = old
end
def test_to_xml_string_with_newlines