summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/yard.yml32
-rw-r--r--.rubocop.yml8
-rw-r--r--.rubocop_todo.yml269
-rw-r--r--CHANGELOG.md2
-rw-r--r--README.md16
-rw-r--r--Rakefile4
-rw-r--r--axlsx.gemspec6
-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.rb7
-rw-r--r--lib/axlsx/content_type/abstract_content_type.rb4
-rw-r--r--lib/axlsx/content_type/content_type.rb6
-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.rb6
-rw-r--r--lib/axlsx/drawing/area_series.rb12
-rw-r--r--lib/axlsx/drawing/axis.rb12
-rw-r--r--lib/axlsx/drawing/bar_3D_chart.rb10
-rw-r--r--lib/axlsx/drawing/bar_chart.rb8
-rw-r--r--lib/axlsx/drawing/bar_series.rb2
-rw-r--r--lib/axlsx/drawing/bubble_chart.rb4
-rw-r--r--lib/axlsx/drawing/bubble_series.rb6
-rw-r--r--lib/axlsx/drawing/cat_axis.rb8
-rw-r--r--lib/axlsx/drawing/chart.rb16
-rw-r--r--lib/axlsx/drawing/d_lbls.rb4
-rw-r--r--lib/axlsx/drawing/drawing.rb108
-rw-r--r--lib/axlsx/drawing/hyperlink.rb10
-rw-r--r--lib/axlsx/drawing/line_3D_chart.rb6
-rw-r--r--lib/axlsx/drawing/line_chart.rb6
-rw-r--r--lib/axlsx/drawing/line_series.rb12
-rw-r--r--lib/axlsx/drawing/marker.rb12
-rw-r--r--lib/axlsx/drawing/num_data.rb4
-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.rb6
-rw-r--r--lib/axlsx/drawing/pic.rb18
-rw-r--r--lib/axlsx/drawing/pie_3D_chart.rb2
-rw-r--r--lib/axlsx/drawing/pie_series.rb6
-rw-r--r--lib/axlsx/drawing/scaling.rb2
-rw-r--r--lib/axlsx/drawing/scatter_chart.rb4
-rw-r--r--lib/axlsx/drawing/scatter_series.rb14
-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_data.rb2
-rw-r--r--lib/axlsx/drawing/str_val.rb4
-rw-r--r--lib/axlsx/drawing/title.rb14
-rw-r--r--lib/axlsx/drawing/two_cell_anchor.rb2
-rw-r--r--lib/axlsx/drawing/view_3D.rb8
-rw-r--r--lib/axlsx/drawing/vml_drawing.rb2
-rw-r--r--lib/axlsx/drawing/vml_shape.rb2
-rw-r--r--lib/axlsx/package.rb102
-rw-r--r--lib/axlsx/rels/relationship.rb6
-rw-r--r--lib/axlsx/rels/relationships.rb2
-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.rb8
-rw-r--r--lib/axlsx/stylesheet/dxf.rb4
-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.rb118
-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.rb19
-rw-r--r--lib/axlsx/util/options_parser.rb2
-rw-r--r--lib/axlsx/util/simple_typed_list.rb12
-rw-r--r--lib/axlsx/util/storage.rb16
-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.rb134
-rw-r--r--lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb69
-rw-r--r--lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/auto_filter/filters.rb4
-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.rb59
-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/col.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/col_breaks.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/color_scale.rb18
-rw-r--r--lib/axlsx/workbook/worksheet/comment.rb4
-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.rb22
-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/dimension.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/icon_set.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/merged_cells.rb6
-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.rb10
-rw-r--r--lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/protected_ranges.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/rich_text_run.rb18
-rw-r--r--lib/axlsx/workbook/worksheet/row.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/row_breaks.rb4
-rw-r--r--lib/axlsx/workbook/worksheet/selection.rb10
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_pr.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_protection.rb10
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_view.rb20
-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.rb44
-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.rb6
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb2
-rw-r--r--lib/caxlsx.rb2
-rwxr-xr-xtest/benchmark.rb17
-rw-r--r--test/content_type/tc_content_type.rb22
-rw-r--r--test/doc_props/tc_app.rb2
-rw-r--r--test/doc_props/tc_core.rb2
-rw-r--r--test/drawing/tc_d_lbls.rb2
-rw-r--r--test/drawing/tc_drawing.rb4
-rw-r--r--test/drawing/tc_hyperlink.rb2
-rw-r--r--test/drawing/tc_one_cell_anchor.rb2
-rw-r--r--test/drawing/tc_pic.rb8
-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.rb8
-rw-r--r--test/workbook/tc_shared_strings_table.rb2
-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_rich_text_run.rb2
-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
159 files changed, 1184 insertions, 1007 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.yml b/.rubocop.yml
index 014f6084..61adf899 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -34,6 +34,9 @@ Lint:
Minitest:
Enabled: true
+Naming:
+ Enabled: true
+
Performance:
Enabled: true
@@ -43,11 +46,6 @@ Security:
Style:
Enabled: true
-# FIXME: remove this rule
-Style/HashSyntax:
- Exclude:
- - 'lib/**/*'
-
Style/Semicolon:
AllowAsExpressionSeparator: true
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index dab9ffb2..16d5bcb6 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -24,11 +24,6 @@ Layout/HashAlignment:
# This cop supports safe autocorrection (--autocorrect).
Lint/AmbiguousOperatorPrecedence:
Exclude:
- - 'lib/axlsx/drawing/area_series.rb'
- - 'lib/axlsx/drawing/line_series.rb'
- - 'lib/axlsx/drawing/pie_series.rb'
- - 'lib/axlsx/workbook/worksheet/dimension.rb'
- - 'lib/axlsx/workbook/worksheet/sheet_protection.rb'
- 'lib/axlsx/workbook/worksheet/worksheet.rb'
# This cop supports unsafe autocorrection (--autocorrect-all).
@@ -53,15 +48,6 @@ Lint/DisjunctiveAssignmentInConstructor:
Exclude:
- 'lib/axlsx/drawing/num_data_source.rb'
-# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
-Lint/DuplicateBranch:
- Exclude:
- - 'lib/axlsx/workbook/worksheet/merged_cells.rb'
-
-Lint/NonLocalExitFromIterator:
- Exclude:
- - 'lib/axlsx/util/validators.rb'
-
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
@@ -77,12 +63,55 @@ Lint/UnusedMethodArgument:
- 'lib/axlsx/package.rb'
- 'lib/axlsx/util/validators.rb'
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: separated, grouped
-Style/AccessorGrouping:
+Naming/AccessorMethodName:
+ Exclude:
+ - 'lib/axlsx/drawing/axes.rb'
+ - 'lib/axlsx/workbook/worksheet/data_validation.rb'
+
+# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
+# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
+# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
+Naming/FileName:
+ Exclude:
+ - 'lib/axlsx/drawing/bar_3D_chart.rb'
+ - 'lib/axlsx/drawing/line_3D_chart.rb'
+ - 'lib/axlsx/drawing/pie_3D_chart.rb'
+ - 'lib/axlsx/drawing/view_3D.rb'
+ - 'test/drawing/tc_bar_3D_chart.rb'
+ - 'test/drawing/tc_pie_3D_chart.rb'
+ - 'test/drawing/tc_view_3D.rb'
+
+# Configuration parameters: EnforcedStyle, AllowedPatterns.
+# SupportedStyles: snake_case, camelCase
+Naming/MethodName:
+ Enabled: false
+
+# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
+# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
+Naming/MethodParameterName:
+ Enabled: false
+
+# Configuration parameters: EnforcedStyle, AllowedIdentifiers, AllowedPatterns.
+# SupportedStyles: snake_case, camelCase
+Naming/VariableName:
+ Enabled: false
+
+# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
+# SupportedStyles: snake_case, normalcase, non_integer
+# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
+Naming/VariableNumber:
Exclude:
- - 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb'
+ - 'lib/axlsx/util/validators.rb'
+ - 'lib/axlsx/workbook/worksheet/cell.rb'
+ - 'lib/axlsx/workbook/worksheet/cell_serializer.rb'
+ - 'lib/axlsx/workbook/worksheet/sheet_protection.rb'
+ - 'test/rels/tc_relationship.rb'
+ - 'test/rels/tc_relationships.rb'
+ - 'test/tc_package.rb'
+ - 'test/workbook/worksheet/tc_cell.rb'
+ - 'test/workbook/worksheet/tc_date_time_converter.rb'
+ - 'test/workbook/worksheet/tc_sheet_view.rb'
+ - 'test/workbook/worksheet/tc_worksheet.rb'
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
@@ -90,37 +119,17 @@ Style/AccessorGrouping:
Style/Alias:
Enabled: false
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: MinBranchesCount.
-Style/CaseLikeIf:
- Exclude:
- - 'lib/axlsx/workbook/worksheet/merged_cells.rb'
-
Style/ClassVars:
Exclude:
- 'lib/axlsx.rb'
- '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:
- 'lib/axlsx/workbook/worksheet/icon_set.rb'
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
-# SupportedStyles: assign_to_condition, assign_inside_condition
-Style/ConditionalAssignment:
- Exclude:
- - 'lib/axlsx/drawing/title.rb'
- - 'lib/axlsx/stylesheet/styles.rb'
- - 'lib/axlsx/workbook/workbook.rb'
- - 'lib/axlsx/workbook/worksheet/data_bar.rb'
-
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
@@ -143,19 +152,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/dimension.rb'
- - 'lib/axlsx/workbook/worksheet/worksheet.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, AllowedMethods, AllowedPatterns.
# SupportedStyles: annotated, template, unannotated
Style/FormatStringToken:
@@ -176,36 +172,11 @@ Style/GuardClause:
- 'lib/axlsx/workbook/worksheet/table.rb'
- 'lib/axlsx/workbook/worksheet/worksheet.rb'
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: AllowedReceivers.
-# AllowedReceivers: Thread.current
-Style/HashEachMethods:
- Exclude:
- - 'lib/axlsx/workbook/worksheet/rich_text_run.rb'
-
-# This cop supports safe autocorrection (--autocorrect).
-# Configuration parameters: AllowIfModifier.
-Style/IfInsideElse:
- Exclude:
- - 'lib/axlsx/stylesheet/styles.rb'
-
# This cop supports safe autocorrection (--autocorrect).
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:
@@ -213,36 +184,6 @@ Style/MultipleComparison:
- 'lib/axlsx/workbook/worksheet/rich_text_run.rb'
- 'test/workbook/tc_workbook_view.rb'
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: literals, strict
-Style/MutableConstant:
- Exclude:
- - 'lib/axlsx/drawing/cat_axis.rb'
- - 'lib/axlsx/drawing/line_3D_chart.rb'
- - 'lib/axlsx/drawing/pic.rb'
- - 'lib/axlsx/drawing/view_3D.rb'
- - 'lib/axlsx/stylesheet/dxf.rb'
- - 'lib/axlsx/util/storage.rb'
- - 'lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb'
- - 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb'
- - 'lib/axlsx/workbook/worksheet/data_bar.rb'
- - 'lib/axlsx/workbook/worksheet/sheet_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
@@ -260,11 +201,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:
@@ -294,14 +230,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:
@@ -320,18 +248,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:
@@ -339,57 +255,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 safe autocorrection (--autocorrect).
-Style/RedundantFileExtensionInRequire:
- Exclude:
- - 'lib/axlsx/content_type/content_type.rb'
- - 'lib/axlsx/drawing/drawing.rb'
- - 'lib/axlsx/rels/relationships.rb'
- - 'lib/axlsx/stylesheet/styles.rb'
- - 'lib/axlsx/workbook/workbook.rb'
- - 'lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb'
- - 'lib/caxlsx.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!
@@ -409,16 +279,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 unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: Mode.
-Style/StringConcatenation:
- Enabled: false
-
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
@@ -431,27 +291,6 @@ Style/StringLiterals:
Style/SymbolArray:
EnforcedStyle: brackets
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments.
-# AllowedMethods: define_method
-Style/SymbolProc:
- Exclude:
- - 'lib/axlsx/drawing/drawing.rb'
- - 'lib/axlsx/stylesheet/styles.rb'
- - 'lib/axlsx/workbook/workbook.rb'
- - 'lib/axlsx/workbook/worksheet/worksheet.rb'
- - 'lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb'
-
-# 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
@@ -469,11 +308,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'
@@ -484,13 +318,6 @@ Style/WhileUntilModifier:
Style/WordArray:
Enabled: false
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: forbid_for_all_comparison_operators, forbid_for_equality_operators_only, require_for_all_comparison_operators, require_for_equality_operators_only
-Style/YodaCondition:
- Exclude:
- - 'lib/axlsx/workbook/worksheet/col.rb'
-
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
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/Rakefile b/Rakefile
index 8125959f..28712c0d 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,13 +1,13 @@
# frozen_string_literal: true
-require File.expand_path(File.dirname(__FILE__) + '/lib/axlsx/version.rb')
+require File.expand_path("#{File.dirname(__FILE__)}/lib/axlsx/version.rb")
task build: :gendoc do
system "gem build axlsx.gemspec"
end
task :benchmark do
- require File.expand_path(File.dirname(__FILE__) + '/test/benchmark.rb')
+ require File.expand_path("#{File.dirname(__FILE__)}/test/benchmark.rb")
end
task :gendoc do
diff --git a/axlsx.gemspec b/axlsx.gemspec
index 5f27130b..7951b416 100644
--- a/axlsx.gemspec
+++ b/axlsx.gemspec
@@ -11,9 +11,9 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.summary = "Excel OOXML (xlsx) with charts, styles, images and autowidth columns."
s.license = 'MIT'
- s.description = <<-eof
- xlsx spreadsheet generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx helps you create beautiful Office Open XML Spreadsheet documents ( Excel, Google Spreadsheets, Numbers, LibreOffice) without having to understand the entire ECMA specification. Check out the README for some examples of how easy it is. Best of all, you can validate your xlsx file before serialization so you know for sure that anything generated is going to load on your client's machine.
- eof
+ s.description = <<~MSG
+ xlsx spreadsheet generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx helps you create beautiful Office Open XML Spreadsheet documents (Excel, Google Spreadsheets, Numbers, LibreOffice) without having to understand the entire ECMA specification. Check out the README for some examples of how easy it is. Best of all, you can validate your xlsx file before serialization so you know for sure that anything generated is going to load on your client's machine.
+ 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' }
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 20af45e0..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
@@ -87,7 +88,7 @@ module Axlsx
letters_str = name[/[A-Z]+/]
# capitalization?!?
- v = letters_str.reverse.chars.reduce({ :base => 1, :i => 0 }) do |val, c|
+ v = letters_str.reverse.chars.reduce({ base: 1, i: 0 }) do |val, c|
val[:i] += ((c.bytes.first - 64) * val[:base])
val[:base] *= 26
@@ -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/content_type.rb b/lib/axlsx/content_type/content_type.rb
index 22763bfb..d2e3bb9e 100644
--- a/lib/axlsx/content_type/content_type.rb
+++ b/lib/axlsx/content_type/content_type.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
module Axlsx
- require 'axlsx/content_type/abstract_content_type.rb'
- require 'axlsx/content_type/default.rb'
- require 'axlsx/content_type/override.rb'
+ require 'axlsx/content_type/abstract_content_type'
+ require 'axlsx/content_type/default'
+ require 'axlsx/content_type/override'
# ContentTypes used in the package. This is automatically managed by the package package.
class ContentType < SimpleTypedList
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 96711cd3..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
@@ -82,7 +82,7 @@ module Axlsx
@series.each { |ser| ser.to_xml_string(str) }
@d_lbls.to_xml_string(str) if @d_lbls
yield if block_given?
- axes.to_xml_string(str, :ids => true)
+ axes.to_xml_string(str, ids: true)
str << "</c:" << node_name << ">"
axes.to_xml_string(str)
end
@@ -92,7 +92,7 @@ module Axlsx
# axis.
# @return [Axes]
def axes
- @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
+ @axes ||= Axes.new(cat_axis: CatAxis, val_axis: ValAxis)
end
end
end
diff --git a/lib/axlsx/drawing/area_series.rb b/lib/axlsx/drawing/area_series.rb
index cf4aaf13..0e3d8928 100644
--- a/lib/axlsx/drawing/area_series.rb
+++ b/lib/axlsx/drawing/area_series.rb
@@ -41,7 +41,7 @@ module Axlsx
@smooth = false
@labels, @data = nil, nil
super(chart, options)
- @labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
+ @labels = AxDataSource.new(data: options[:labels]) unless options[:labels].nil?
@data = NumDataSource.new(options) unless options[:data].nil?
end
@@ -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
@@ -89,12 +89,12 @@ module Axlsx
if !@show_marker
str << '<c:marker><c:symbol val="none"/></c:marker>'
elsif @marker_symbol != :default
- str << '<c:marker><c:symbol val="' + @marker_symbol.to_s + '"/></c:marker>'
+ str << '<c:marker><c:symbol val="' << @marker_symbol.to_s << '"/></c:marker>'
end
@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 10ddce1f..ed3df5f1 100644
--- a/lib/axlsx/drawing/axis.rb
+++ b/lib/axlsx/drawing/axis.rb
@@ -15,7 +15,7 @@ module Axlsx
@id = rand(8**8)
@format_code = "General"
@delete = @label_rotation = 0
- @scaling = Scaling.new(:orientation => :minMax)
+ @scaling = Scaling.new(orientation: :minMax)
@title = @color = nil
self.ax_pos = :b
self.tick_lbl_pos = :nextTo
@@ -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 fe347d7c..4b688668 100644
--- a/lib/axlsx/drawing/bar_3D_chart.rb
+++ b/lib/axlsx/drawing/bar_3D_chart.rb
@@ -77,7 +77,7 @@ module Axlsx
@gap_width, @gap_depth, @shape = nil, nil, nil
super(frame, options)
@series_type = BarSeries
- @view_3D = View3D.new({ :r_ang_ax => 1 }.merge(options))
+ @view_3D = View3D.new({ r_ang_ax: 1 }.merge(options))
@d_lbls = nil
end
@@ -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=
@@ -131,7 +131,7 @@ module Axlsx
str << '<c:gapWidth val="' << @gap_width.to_s << '"/>' unless @gap_width.nil?
str << '<c:gapDepth val="' << @gap_depth.to_s << '"/>' unless @gap_depth.nil?
str << '<c:shape val="' << @shape.to_s << '"/>' unless @shape.nil?
- axes.to_xml_string(str, :ids => true)
+ axes.to_xml_string(str, ids: true)
str << '</c:bar3DChart>'
axes.to_xml_string(str)
end
@@ -141,7 +141,7 @@ module Axlsx
# category axes specified via axes[:val_axes] and axes[:cat_axis]
# @return [Axes]
def axes
- @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
+ @axes ||= Axes.new(cat_axis: CatAxis, val_axis: ValAxis)
end
end
end
diff --git a/lib/axlsx/drawing/bar_chart.rb b/lib/axlsx/drawing/bar_chart.rb
index 237ffdb3..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
@@ -121,7 +121,7 @@ module Axlsx
str << '<c:overlap val="' << @overlap.to_s << '"/>' unless @overlap.nil?
str << '<c:gapWidth val="' << @gap_width.to_s << '"/>' unless @gap_width.nil?
str << '<c:shape val="' << @shape.to_s << '"/>' unless @shape.nil?
- axes.to_xml_string(str, :ids => true)
+ axes.to_xml_string(str, ids: true)
str << '</c:barChart>'
axes.to_xml_string(str)
end
@@ -131,7 +131,7 @@ module Axlsx
# category axes specified via axes[:val_axes] and axes[:cat_axis]
# @return [Axes]
def axes
- @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
+ @axes ||= Axes.new(cat_axis: CatAxis, val_axis: ValAxis)
end
end
end
diff --git a/lib/axlsx/drawing/bar_series.rb b/lib/axlsx/drawing/bar_series.rb
index 483a0c43..11a315e2 100644
--- a/lib/axlsx/drawing/bar_series.rb
+++ b/lib/axlsx/drawing/bar_series.rb
@@ -38,7 +38,7 @@ module Axlsx
@shape = :box
@colors = []
super(chart, options)
- self.labels = AxDataSource.new({ :data => options[:labels] }) unless options[:labels].nil?
+ self.labels = AxDataSource.new({ data: options[:labels] }) unless options[:labels].nil?
self.data = NumDataSource.new(options) unless options[:data].nil?
end
diff --git a/lib/axlsx/drawing/bubble_chart.rb b/lib/axlsx/drawing/bubble_chart.rb
index 727f89a7..6b879e05 100644
--- a/lib/axlsx/drawing/bubble_chart.rb
+++ b/lib/axlsx/drawing/bubble_chart.rb
@@ -41,7 +41,7 @@ module Axlsx
str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
@series.each { |ser| ser.to_xml_string(str) }
d_lbls.to_xml_string(str) if @d_lbls
- axes.to_xml_string(str, :ids => true)
+ axes.to_xml_string(str, ids: true)
str << '</c:bubbleChart>'
axes.to_xml_string(str)
end
@@ -52,7 +52,7 @@ module Axlsx
# a y_val_axis
# @return [Axes]
def axes
- @axes ||= Axes.new(:x_val_axis => ValAxis, :y_val_axis => ValAxis)
+ @axes ||= Axes.new(x_val_axis: ValAxis, y_val_axis: ValAxis)
end
end
end
diff --git a/lib/axlsx/drawing/bubble_series.rb b/lib/axlsx/drawing/bubble_series.rb
index b5903259..a30612ec 100644
--- a/lib/axlsx/drawing/bubble_series.rb
+++ b/lib/axlsx/drawing/bubble_series.rb
@@ -28,9 +28,9 @@ module Axlsx
def initialize(chart, options = {})
@xData, @yData, @bubbleSize = nil
super(chart, options)
- @xData = AxDataSource.new(:tag_name => :xVal, :data => options[:xData]) unless options[:xData].nil?
- @yData = NumDataSource.new({ :tag_name => :yVal, :data => options[:yData] }) unless options[:yData].nil?
- @bubbleSize = NumDataSource.new({ :tag_name => :bubbleSize, :data => options[:bubbleSize] }) unless options[:bubbleSize].nil?
+ @xData = AxDataSource.new(tag_name: :xVal, data: options[:xData]) unless options[:xData].nil?
+ @yData = NumDataSource.new({ tag_name: :yVal, data: options[:yData] }) unless options[:yData].nil?
+ @bubbleSize = NumDataSource.new({ tag_name: :bubbleSize, data: options[:bubbleSize] }) unless options[:bubbleSize].nil?
end
# @see color
diff --git a/lib/axlsx/drawing/cat_axis.rb b/lib/axlsx/drawing/cat_axis.rb
index 2f40f29f..d078eb6f 100644
--- a/lib/axlsx/drawing/cat_axis.rb
+++ b/lib/axlsx/drawing/cat_axis.rb
@@ -42,18 +42,18 @@ module Axlsx
alias :tickMarkSkip :tick_mark_skip
# regex for validating label offset
- LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)/
+ 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 436319fb..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
@@ -187,19 +187,19 @@ module Axlsx
# Assigns a background color to chart area
def bg_color=(v)
- DataTypeValidator.validate(:color, Color, Color.new(:rgb => v))
+ DataTypeValidator.validate(:color, Color, Color.new(rgb: v))
@bg_color = v
end
# 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 ef532974..997a7af0 100644
--- a/lib/axlsx/drawing/drawing.rb
+++ b/lib/axlsx/drawing/drawing.rb
@@ -1,55 +1,55 @@
# frozen_string_literal: true
module Axlsx
- require 'axlsx/drawing/d_lbls.rb'
- require 'axlsx/drawing/title.rb'
- require 'axlsx/drawing/series_title.rb'
- require 'axlsx/drawing/series.rb'
- require 'axlsx/drawing/pie_series.rb'
- require 'axlsx/drawing/bar_series.rb'
- require 'axlsx/drawing/line_series.rb'
- require 'axlsx/drawing/scatter_series.rb'
- require 'axlsx/drawing/bubble_series.rb'
- require 'axlsx/drawing/area_series.rb'
-
- require 'axlsx/drawing/scaling.rb'
- require 'axlsx/drawing/axis.rb'
-
- require 'axlsx/drawing/str_val.rb'
- require 'axlsx/drawing/num_val.rb'
- require 'axlsx/drawing/str_data.rb'
- require 'axlsx/drawing/num_data.rb'
- require 'axlsx/drawing/num_data_source.rb'
- require 'axlsx/drawing/ax_data_source.rb'
-
- require 'axlsx/drawing/ser_axis.rb'
- require 'axlsx/drawing/cat_axis.rb'
- require 'axlsx/drawing/val_axis.rb'
- require 'axlsx/drawing/axes.rb'
-
- require 'axlsx/drawing/marker.rb'
-
- require 'axlsx/drawing/one_cell_anchor.rb'
- require 'axlsx/drawing/two_cell_anchor.rb'
- require 'axlsx/drawing/graphic_frame.rb'
-
- require 'axlsx/drawing/view_3D.rb'
- require 'axlsx/drawing/chart.rb'
- require 'axlsx/drawing/pie_3D_chart.rb'
- require 'axlsx/drawing/bar_3D_chart.rb'
- require 'axlsx/drawing/bar_chart.rb'
- require 'axlsx/drawing/line_chart.rb'
- require 'axlsx/drawing/line_3D_chart.rb'
- require 'axlsx/drawing/scatter_chart.rb'
- require 'axlsx/drawing/bubble_chart.rb'
- require 'axlsx/drawing/area_chart.rb'
-
- require 'axlsx/drawing/picture_locking.rb'
- require 'axlsx/drawing/pic.rb'
- require 'axlsx/drawing/hyperlink.rb'
-
- require 'axlsx/drawing/vml_drawing.rb'
- require 'axlsx/drawing/vml_shape.rb'
+ require 'axlsx/drawing/d_lbls'
+ require 'axlsx/drawing/title'
+ require 'axlsx/drawing/series_title'
+ require 'axlsx/drawing/series'
+ require 'axlsx/drawing/pie_series'
+ require 'axlsx/drawing/bar_series'
+ require 'axlsx/drawing/line_series'
+ require 'axlsx/drawing/scatter_series'
+ require 'axlsx/drawing/bubble_series'
+ require 'axlsx/drawing/area_series'
+
+ require 'axlsx/drawing/scaling'
+ require 'axlsx/drawing/axis'
+
+ require 'axlsx/drawing/str_val'
+ require 'axlsx/drawing/num_val'
+ require 'axlsx/drawing/str_data'
+ require 'axlsx/drawing/num_data'
+ require 'axlsx/drawing/num_data_source'
+ require 'axlsx/drawing/ax_data_source'
+
+ require 'axlsx/drawing/ser_axis'
+ require 'axlsx/drawing/cat_axis'
+ require 'axlsx/drawing/val_axis'
+ require 'axlsx/drawing/axes'
+
+ require 'axlsx/drawing/marker'
+
+ require 'axlsx/drawing/one_cell_anchor'
+ require 'axlsx/drawing/two_cell_anchor'
+ require 'axlsx/drawing/graphic_frame'
+
+ require 'axlsx/drawing/view_3D'
+ require 'axlsx/drawing/chart'
+ require 'axlsx/drawing/pie_3D_chart'
+ require 'axlsx/drawing/bar_3D_chart'
+ require 'axlsx/drawing/bar_chart'
+ require 'axlsx/drawing/line_chart'
+ require 'axlsx/drawing/line_3D_chart'
+ require 'axlsx/drawing/scatter_chart'
+ require 'axlsx/drawing/bubble_chart'
+ require 'axlsx/drawing/area_chart'
+
+ require 'axlsx/drawing/picture_locking'
+ require 'axlsx/drawing/pic'
+ require 'axlsx/drawing/hyperlink'
+
+ require 'axlsx/drawing/vml_drawing'
+ require 'axlsx/drawing/vml_shape'
# A Drawing is a canvas for charts and images. Each worksheet has a single drawing that manages anchors.
# The anchors reference the charts or images via graphical frames. This is not a trivial relationship so please do follow the advice in the note.
@@ -108,15 +108,15 @@ 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.map { |a| a.hyperlink }
+ links = images.select { |a| a.hyperlink.is_a?(Hyperlink) }
+ links.map(&:hyperlink)
end
# An array of image objects that are associated with this drawing's anchors
# @return [Array]
def images
images = @anchors.select { |a| a.object.is_a?(Pic) }
- images.map { |a| a.object }
+ images.map(&:object)
end
# The index of this drawing in the owning workbooks's drawings collection.
@@ -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 0d9eb4f7..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]
@@ -86,14 +86,14 @@ module Axlsx
# The relationship object for this hyperlink.
# @return [Relationship]
def relationship
- Relationship.new(self, HYPERLINK_R, href, :target_mode => :External)
+ Relationship.new(self, HYPERLINK_R, href, target_mode: :External)
end
# Serializes the object
# @param [String] str
# @return [String]
def to_xml_string(str = +'')
- serialized_tag 'a:hlinkClick', str, { :'r:id' => relationship.Id, :'xmlns:r' => XML_NS_R }
+ serialized_tag 'a:hlinkClick', str, { 'r:id': relationship.Id, 'xmlns:r': XML_NS_R }
end
end
end
diff --git a/lib/axlsx/drawing/line_3D_chart.rb b/lib/axlsx/drawing/line_3D_chart.rb
index f9f9606e..54f0170f 100644
--- a/lib/axlsx/drawing/line_3D_chart.rb
+++ b/lib/axlsx/drawing/line_3D_chart.rb
@@ -26,7 +26,7 @@ module Axlsx
alias :gapDepth :gap_depth
# validation regex for gap amount percent
- GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
+ GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/.freeze
# the category axis
# @return [Axis]
@@ -42,7 +42,7 @@ module Axlsx
# @see View3D
def initialize(frame, options = {})
@gap_depth = nil
- @view_3D = View3D.new({ :r_ang_ax => 1 }.merge(options))
+ @view_3D = View3D.new({ r_ang_ax: 1 }.merge(options))
super(frame, options)
axes.add_axis :ser_axis, SerAxis
end
@@ -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 21327820..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
@@ -82,7 +82,7 @@ module Axlsx
@series.each { |ser| ser.to_xml_string(str) }
@d_lbls.to_xml_string(str) if @d_lbls
yield if block_given?
- axes.to_xml_string(str, :ids => true)
+ axes.to_xml_string(str, ids: true)
str << "</c:" << node_name << ">"
axes.to_xml_string(str)
end
@@ -92,7 +92,7 @@ module Axlsx
# axis.
# @return [Axes]
def axes
- @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
+ @axes ||= Axes.new(cat_axis: CatAxis, val_axis: ValAxis)
end
end
end
diff --git a/lib/axlsx/drawing/line_series.rb b/lib/axlsx/drawing/line_series.rb
index fbed4000..13492419 100644
--- a/lib/axlsx/drawing/line_series.rb
+++ b/lib/axlsx/drawing/line_series.rb
@@ -41,7 +41,7 @@ module Axlsx
@smooth = false
@labels, @data = nil, nil
super(chart, options)
- @labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
+ @labels = AxDataSource.new(data: options[:labels]) unless options[:labels].nil?
@data = NumDataSource.new(options) unless options[:data].nil?
end
@@ -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
@@ -89,12 +89,12 @@ module Axlsx
if !@show_marker
str << '<c:marker><c:symbol val="none"/></c:marker>'
elsif @marker_symbol != :default
- str << '<c:marker><c:symbol val="' + @marker_symbol.to_s + '"/></c:marker>'
+ str << '<c:marker><c:symbol val="' << @marker_symbol.to_s << '"/></c:marker>'
end
@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 fdcf505c..3ad23cb4 100644
--- a/lib/axlsx/drawing/num_data.rb
+++ b/lib/axlsx/drawing/num_data.rb
@@ -25,13 +25,13 @@ module Axlsx
@tag_name = values.first.is_a?(Cell) ? :numCache : :numLit
values.each do |value|
value = value.is_formula? ? 0 : value.value if value.is_a?(Cell)
- @pt << NumVal.new(:v => value)
+ @pt << NumVal.new(v: value)
end
end
# @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 59d0d972..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]
@@ -93,7 +93,7 @@ module Axlsx
def ext
cy = @height * 914400 / 96
cx = @width * 914400 / 96
- { :cy => cy, :cx => cx }
+ { cy: cy, cx: cx }
end
end
end
diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb
index fa08bd83..630d8d96 100644
--- a/lib/axlsx/drawing/pic.rb
+++ b/lib/axlsx/drawing/pic.rb
@@ -30,7 +30,7 @@ module Axlsx
end
# allowed mime types
- ALLOWED_MIME_TYPES = %w(image/jpeg image/png image/gif)
+ ALLOWED_MIME_TYPES = %w(image/jpeg image/png image/gif).freeze
# The name to use for this picture
# @return [String]
@@ -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
@@ -223,7 +223,7 @@ module Axlsx
def use_one_cell_anchor
return if @anchor.is_a?(OneCellAnchor)
- new_anchor = OneCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row])
+ new_anchor = OneCellAnchor.new(@anchor.drawing, start_at: [@anchor.from.col, @anchor.from.row])
swap_anchor(new_anchor)
end
@@ -231,7 +231,7 @@ module Axlsx
def use_two_cell_anchor
return if @anchor.is_a?(TwoCellAnchor)
- new_anchor = TwoCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row])
+ new_anchor = TwoCellAnchor.new(@anchor.drawing, start_at: [@anchor.from.col, @anchor.from.row])
swap_anchor(new_anchor)
end
diff --git a/lib/axlsx/drawing/pie_3D_chart.rb b/lib/axlsx/drawing/pie_3D_chart.rb
index aeb002d8..7fa87cde 100644
--- a/lib/axlsx/drawing/pie_3D_chart.rb
+++ b/lib/axlsx/drawing/pie_3D_chart.rb
@@ -24,7 +24,7 @@ module Axlsx
@vary_colors = true
super(frame, options)
@series_type = PieSeries
- @view_3D = View3D.new({ :rot_x => 30, :perspective => 30 }.merge(options))
+ @view_3D = View3D.new({ rot_x: 30, perspective: 30 }.merge(options))
@d_lbls = nil
end
diff --git a/lib/axlsx/drawing/pie_series.rb b/lib/axlsx/drawing/pie_series.rb
index f3edd1e9..416cd93c 100644
--- a/lib/axlsx/drawing/pie_series.rb
+++ b/lib/axlsx/drawing/pie_series.rb
@@ -31,7 +31,7 @@ module Axlsx
@explosion = nil
@colors = []
super(chart, options)
- self.labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
+ self.labels = AxDataSource.new(data: options[:labels]) unless options[:labels].nil?
self.data = NumDataSource.new(options) unless options[:data].nil?
end
@@ -39,14 +39,14 @@ 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
# @return [String]
def to_xml_string(str = +'')
super(str) do
- str << '<c:explosion val="' + @explosion.to_s + '"/>' unless @explosion.nil?
+ str << '<c:explosion val="' << @explosion.to_s << '"/>' unless @explosion.nil?
colors.each_with_index do |c, index|
str << '<c:dPt>'
str << '<c:idx val="' << index.to_s << '"/>'
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_chart.rb b/lib/axlsx/drawing/scatter_chart.rb
index 60b7c5b3..b9fcffbd 100644
--- a/lib/axlsx/drawing/scatter_chart.rb
+++ b/lib/axlsx/drawing/scatter_chart.rb
@@ -56,7 +56,7 @@ module Axlsx
str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
@series.each { |ser| ser.to_xml_string(str) }
d_lbls.to_xml_string(str) if @d_lbls
- axes.to_xml_string(str, :ids => true)
+ axes.to_xml_string(str, ids: true)
str << '</c:scatterChart>'
axes.to_xml_string(str)
end
@@ -67,7 +67,7 @@ module Axlsx
# a y_val_axis
# @return [Axes]
def axes
- @axes ||= Axes.new(:x_val_axis => ValAxis, :y_val_axis => ValAxis)
+ @axes ||= Axes.new(x_val_axis: ValAxis, y_val_axis: ValAxis)
end
end
end
diff --git a/lib/axlsx/drawing/scatter_series.rb b/lib/axlsx/drawing/scatter_series.rb
index 9c6e12f2..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?
@@ -51,8 +51,8 @@ module Axlsx
@marker_symbol = :default
super(chart, options)
- @xData = AxDataSource.new(:tag_name => :xVal, :data => options[:xData]) unless options[:xData].nil?
- @yData = NumDataSource.new({ :tag_name => :yVal, :data => options[:yData] }) unless options[:yData].nil?
+ @xData = AxDataSource.new(tag_name: :xVal, data: options[:xData]) unless options[:xData].nil?
+ @yData = NumDataSource.new({ tag_name: :yVal, data: options[:yData] }) unless options[:yData].nil?
end
# @see color
@@ -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
@@ -121,7 +121,7 @@ module Axlsx
if !@show_marker
'<c:symbol val="none"/>'
elsif @marker_symbol != :default
- '<c:symbol val="' + @marker_symbol.to_s + '"/>'
+ '<c:symbol val="' << @marker_symbol.to_s << '"/>'
end.to_s
end
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_data.rb b/lib/axlsx/drawing/str_data.rb
index 5ab15c39..88c84c20 100644
--- a/lib/axlsx/drawing/str_data.rb
+++ b/lib/axlsx/drawing/str_data.rb
@@ -22,7 +22,7 @@ module Axlsx
@tag_name = values.first.is_a?(Cell) ? :strCache : :strLit
values.each do |value|
v = value.is_a?(Cell) ? value.value : value
- @pt << @type.new(:v => v)
+ @pt << @type.new(v: v)
end
end
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 2e4037fb..8fa79e52 100644
--- a/lib/axlsx/drawing/title.rb
+++ b/lib/axlsx/drawing/title.rb
@@ -20,11 +20,11 @@ module Axlsx
def initialize(title = "", title_size = "")
self.cell = title if title.is_a?(Cell)
self.text = title.to_s unless title.is_a?(Cell)
- if title_size.to_s.empty?
- self.text_size = "1600"
- else
- self.text_size = title_size.to_s
- end
+ self.text_size = if title_size.to_s.empty?
+ "1600"
+ else
+ title_size.to_s
+ end
end
# @see text
@@ -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/two_cell_anchor.rb b/lib/axlsx/drawing/two_cell_anchor.rb
index bebfd28c..f017311b 100644
--- a/lib/axlsx/drawing/two_cell_anchor.rb
+++ b/lib/axlsx/drawing/two_cell_anchor.rb
@@ -35,7 +35,7 @@ module Axlsx
def initialize(drawing, options = {})
@drawing = drawing
drawing.anchors << self
- @from, @to = Marker.new, Marker.new(:col => 5, :row => 10)
+ @from, @to = Marker.new, Marker.new(col: 5, row: 10)
parse_options options
# bit of a hack to work around the fact that the coords for start at and end at
diff --git a/lib/axlsx/drawing/view_3D.rb b/lib/axlsx/drawing/view_3D.rb
index 9b1b5cb2..c3f5838d 100644
--- a/lib/axlsx/drawing/view_3D.rb
+++ b/lib/axlsx/drawing/view_3D.rb
@@ -18,10 +18,10 @@ module Axlsx
end
# Validation for hPercent
- H_PERCENT_REGEX = /0*(([5-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)/
+ H_PERCENT_REGEX = /0*(([5-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)/.freeze
# validation for depthPercent
- DEPTH_PERCENT_REGEX = /0*(([2-9][0-9])|([1-9][0-9][0-9])|(1[0-9][0-9][0-9])|2000)/
+ DEPTH_PERCENT_REGEX = /0*(([2-9][0-9])|([1-9][0-9][0-9])|(1[0-9][0-9][0-9])|2000)/.freeze
# x rotation for the chart
# must be between -90 and 90
@@ -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 20195ddc..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|
@@ -216,57 +216,57 @@ module Axlsx
# @private
def parts
parts = [
- { :entry => "xl/#{STYLES_PN}", :doc => workbook.styles, :schema => SML_XSD },
- { :entry => CORE_PN, :doc => @core, :schema => CORE_XSD },
- { :entry => APP_PN, :doc => @app, :schema => APP_XSD },
- { :entry => WORKBOOK_RELS_PN, :doc => workbook.relationships, :schema => RELS_XSD },
- { :entry => WORKBOOK_PN, :doc => workbook, :schema => SML_XSD }
+ { entry: "xl/#{STYLES_PN}", doc: workbook.styles, schema: SML_XSD },
+ { entry: CORE_PN, doc: @core, schema: CORE_XSD },
+ { entry: APP_PN, doc: @app, schema: APP_XSD },
+ { entry: WORKBOOK_RELS_PN, doc: workbook.relationships, schema: RELS_XSD },
+ { entry: WORKBOOK_PN, doc: workbook, schema: SML_XSD }
]
workbook.drawings.each do |drawing|
- parts << { :entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships, :schema => RELS_XSD }
- parts << { :entry => "xl/#{drawing.pn}", :doc => drawing, :schema => DRAWING_XSD }
+ parts << { entry: "xl/#{drawing.rels_pn}", doc: drawing.relationships, schema: RELS_XSD }
+ parts << { entry: "xl/#{drawing.pn}", doc: drawing, schema: DRAWING_XSD }
end
workbook.tables.each do |table|
- parts << { :entry => "xl/#{table.pn}", :doc => table, :schema => SML_XSD }
+ parts << { entry: "xl/#{table.pn}", doc: table, schema: SML_XSD }
end
workbook.pivot_tables.each do |pivot_table|
cache_definition = pivot_table.cache_definition
- parts << { :entry => "xl/#{pivot_table.rels_pn}", :doc => pivot_table.relationships, :schema => RELS_XSD }
- parts << { :entry => "xl/#{pivot_table.pn}", :doc => pivot_table } # , :schema => SML_XSD}
- parts << { :entry => "xl/#{cache_definition.pn}", :doc => cache_definition } # , :schema => SML_XSD}
+ parts << { entry: "xl/#{pivot_table.rels_pn}", doc: pivot_table.relationships, schema: RELS_XSD }
+ parts << { entry: "xl/#{pivot_table.pn}", doc: pivot_table } # , :schema => SML_XSD}
+ parts << { entry: "xl/#{cache_definition.pn}", doc: cache_definition } # , :schema => SML_XSD}
end
workbook.comments.each do |comment|
unless comment.empty?
- parts << { :entry => "xl/#{comment.pn}", :doc => comment, :schema => SML_XSD }
- parts << { :entry => "xl/#{comment.vml_drawing.pn}", :doc => comment.vml_drawing, :schema => nil }
+ parts << { entry: "xl/#{comment.pn}", doc: comment, schema: SML_XSD }
+ parts << { entry: "xl/#{comment.vml_drawing.pn}", doc: comment.vml_drawing, schema: nil }
end
end
workbook.charts.each do |chart|
- parts << { :entry => "xl/#{chart.pn}", :doc => chart, :schema => DRAWING_XSD }
+ parts << { entry: "xl/#{chart.pn}", doc: chart, schema: DRAWING_XSD }
end
workbook.images.each do |image|
- parts << { :entry => "xl/#{image.pn}", :path => image.image_src } unless image.remote?
+ parts << { entry: "xl/#{image.pn}", path: image.image_src } unless image.remote?
end
if use_shared_strings
- parts << { :entry => "xl/#{SHARED_STRINGS_PN}", :doc => workbook.shared_strings, :schema => SML_XSD }
+ parts << { entry: "xl/#{SHARED_STRINGS_PN}", doc: workbook.shared_strings, schema: SML_XSD }
end
workbook.worksheets.each do |sheet|
- parts << { :entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships, :schema => RELS_XSD }
- parts << { :entry => "xl/#{sheet.pn}", :doc => sheet, :schema => SML_XSD }
+ parts << { entry: "xl/#{sheet.rels_pn}", doc: sheet.relationships, schema: RELS_XSD }
+ parts << { entry: "xl/#{sheet.pn}", doc: sheet, schema: SML_XSD }
end
# Sort parts for correct MIME detection
[
- { :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)
+ { 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
]
end
@@ -292,41 +292,41 @@ module Axlsx
def content_types
c_types = base_content_types
workbook.drawings.each do |drawing|
- c_types << Axlsx::Override.new(:PartName => "/xl/#{drawing.pn}",
- :ContentType => DRAWING_CT)
+ c_types << Axlsx::Override.new(PartName: "/xl/#{drawing.pn}",
+ ContentType: DRAWING_CT)
end
workbook.charts.each do |chart|
- c_types << Axlsx::Override.new(:PartName => "/xl/#{chart.pn}",
- :ContentType => CHART_CT)
+ c_types << Axlsx::Override.new(PartName: "/xl/#{chart.pn}",
+ ContentType: CHART_CT)
end
workbook.tables.each do |table|
- c_types << Axlsx::Override.new(:PartName => "/xl/#{table.pn}",
- :ContentType => TABLE_CT)
+ c_types << Axlsx::Override.new(PartName: "/xl/#{table.pn}",
+ ContentType: TABLE_CT)
end
workbook.pivot_tables.each do |pivot_table|
- c_types << Axlsx::Override.new(:PartName => "/xl/#{pivot_table.pn}",
- :ContentType => PIVOT_TABLE_CT)
- c_types << Axlsx::Override.new(:PartName => "/xl/#{pivot_table.cache_definition.pn}",
- :ContentType => PIVOT_TABLE_CACHE_DEFINITION_CT)
+ c_types << Axlsx::Override.new(PartName: "/xl/#{pivot_table.pn}",
+ ContentType: PIVOT_TABLE_CT)
+ c_types << Axlsx::Override.new(PartName: "/xl/#{pivot_table.cache_definition.pn}",
+ ContentType: PIVOT_TABLE_CACHE_DEFINITION_CT)
end
workbook.comments.each do |comment|
unless comment.empty?
- c_types << Axlsx::Override.new(:PartName => "/xl/#{comment.pn}",
- :ContentType => COMMENT_CT)
+ c_types << Axlsx::Override.new(PartName: "/xl/#{comment.pn}",
+ ContentType: COMMENT_CT)
end
end
unless workbook.comments.empty?
- c_types << Axlsx::Default.new(:Extension => "vml", :ContentType => VML_DRAWING_CT)
+ c_types << Axlsx::Default.new(Extension: "vml", ContentType: VML_DRAWING_CT)
end
workbook.worksheets.each do |sheet|
- c_types << Axlsx::Override.new(:PartName => "/xl/#{sheet.pn}",
- :ContentType => WORKSHEET_CT)
+ c_types << Axlsx::Override.new(PartName: "/xl/#{sheet.pn}",
+ ContentType: WORKSHEET_CT)
end
exts = workbook.images.map { |image| image.extname.downcase }
exts.uniq.each do |ext|
@@ -337,11 +337,11 @@ module Axlsx
elsif ext == PNG_EX
PNG_CT
end
- c_types << Axlsx::Default.new(:ContentType => ct, :Extension => ext)
+ c_types << Axlsx::Default.new(ContentType: ct, Extension: ext)
end
if use_shared_strings
- c_types << Axlsx::Override.new(:PartName => "/xl/#{SHARED_STRINGS_PN}",
- :ContentType => SHARED_STRINGS_CT)
+ c_types << Axlsx::Override.new(PartName: "/xl/#{SHARED_STRINGS_PN}",
+ ContentType: SHARED_STRINGS_CT)
end
c_types
end
@@ -351,12 +351,12 @@ module Axlsx
# @private
def base_content_types
c_types = ContentType.new
- c_types << Default.new(:ContentType => RELS_CT, :Extension => RELS_EX)
- c_types << Default.new(:Extension => XML_EX, :ContentType => XML_CT)
- c_types << Override.new(:PartName => "/#{APP_PN}", :ContentType => APP_CT)
- c_types << Override.new(:PartName => "/#{CORE_PN}", :ContentType => CORE_CT)
- c_types << Override.new(:PartName => "/xl/#{STYLES_PN}", :ContentType => STYLES_CT)
- c_types << Axlsx::Override.new(:PartName => "/#{WORKBOOK_PN}", :ContentType => WORKBOOK_CT)
+ c_types << Default.new(ContentType: RELS_CT, Extension: RELS_EX)
+ c_types << Default.new(Extension: XML_EX, ContentType: XML_CT)
+ c_types << Override.new(PartName: "/#{APP_PN}", ContentType: APP_CT)
+ c_types << Override.new(PartName: "/#{CORE_PN}", ContentType: CORE_CT)
+ c_types << Override.new(PartName: "/xl/#{STYLES_PN}", ContentType: STYLES_CT)
+ c_types << Axlsx::Override.new(PartName: "/#{WORKBOOK_PN}", ContentType: WORKBOOK_CT)
c_types.lock
c_types
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/rels/relationships.rb b/lib/axlsx/rels/relationships.rb
index 3aa9c1bf..910f2473 100644
--- a/lib/axlsx/rels/relationships.rb
+++ b/lib/axlsx/rels/relationships.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module Axlsx
- require 'axlsx/rels/relationship.rb'
+ require 'axlsx/rels/relationship'
# Relationships are a collection of Relations that define how package parts are related.
# @note The package automatically manages releationships.
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 24fe3bc3..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
@@ -73,7 +73,7 @@ module Axlsx
# @param [String] str
# @return [String]
def to_xml_string(str = +'', tag_name = 'color')
- serialized_tag('' + tag_name + '', str)
+ serialized_tag(tag_name.to_s, str)
end
end
end
diff --git a/lib/axlsx/stylesheet/dxf.rb b/lib/axlsx/stylesheet/dxf.rb
index 8c32a75f..dc9c2e1c 100644
--- a/lib/axlsx/stylesheet/dxf.rb
+++ b/lib/axlsx/stylesheet/dxf.rb
@@ -8,7 +8,7 @@ module Axlsx
# The order in which the child elements is put in the XML seems to
# be important for Excel
- CHILD_ELEMENTS = [:font, :numFmt, :fill, :alignment, :border, :protection]
+ CHILD_ELEMENTS = [:font, :numFmt, :fill, :alignment, :border, :protection].freeze
# does not support extList (ExtensionList)
# The cell alignment for this style
@@ -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 625f6a02..d9c5683a 100644
--- a/lib/axlsx/stylesheet/styles.rb
+++ b/lib/axlsx/stylesheet/styles.rb
@@ -1,23 +1,23 @@
# frozen_string_literal: true
module Axlsx
- require 'axlsx/stylesheet/border.rb'
- require 'axlsx/stylesheet/border_pr.rb'
- require 'axlsx/stylesheet/cell_alignment.rb'
- require 'axlsx/stylesheet/cell_style.rb'
- require 'axlsx/stylesheet/color.rb'
- require 'axlsx/stylesheet/fill.rb'
- require 'axlsx/stylesheet/font.rb'
- require 'axlsx/stylesheet/gradient_fill.rb'
- require 'axlsx/stylesheet/gradient_stop.rb'
- require 'axlsx/stylesheet/num_fmt.rb'
- require 'axlsx/stylesheet/pattern_fill.rb'
- require 'axlsx/stylesheet/table_style.rb'
- require 'axlsx/stylesheet/table_styles.rb'
- require 'axlsx/stylesheet/table_style_element.rb'
- require 'axlsx/stylesheet/dxf.rb'
- require 'axlsx/stylesheet/xf.rb'
- require 'axlsx/stylesheet/cell_protection.rb'
+ require 'axlsx/stylesheet/border'
+ require 'axlsx/stylesheet/border_pr'
+ require 'axlsx/stylesheet/cell_alignment'
+ require 'axlsx/stylesheet/cell_style'
+ require 'axlsx/stylesheet/color'
+ require 'axlsx/stylesheet/fill'
+ require 'axlsx/stylesheet/font'
+ require 'axlsx/stylesheet/gradient_fill'
+ require 'axlsx/stylesheet/gradient_stop'
+ require 'axlsx/stylesheet/num_fmt'
+ require 'axlsx/stylesheet/pattern_fill'
+ require 'axlsx/stylesheet/table_style'
+ require 'axlsx/stylesheet/table_styles'
+ require 'axlsx/stylesheet/table_style_element'
+ require 'axlsx/stylesheet/dxf'
+ require 'axlsx/stylesheet/xf'
+ require 'axlsx/stylesheet/cell_protection'
# The Styles class manages worksheet styles
# In addition to creating the require style objects for a valid xlsx package, this class provides the key mechanism for adding styles to your workbook, and safely applying them to the cells of your worksheet.
@@ -265,12 +265,12 @@ module Axlsx
alignment = parse_alignment_options options
protection = parse_protection_options options
- case options[:type]
- when :dxf
- style = Dxf.new :fill => fill, :font => font, :numFmt => numFmt, :border => border, :alignment => alignment, :protection => protection
- else
- style = Xf.new :fillId => fill || 0, :fontId => font || 0, :numFmtId => numFmt || 0, :borderId => border || 0, :alignment => alignment, :protection => protection, :applyFill => !fill.nil?, :applyFont => !font.nil?, :applyNumberFormat => !numFmt.nil?, :applyBorder => !border.nil?, :applyAlignment => !alignment.nil?, :applyProtection => !protection.nil?
- end
+ style = case options[:type]
+ when :dxf
+ Dxf.new fill: fill, font: font, numFmt: numFmt, border: border, alignment: alignment, protection: protection
+ else
+ Xf.new fillId: fill || 0, fontId: font || 0, numFmtId: numFmt || 0, borderId: border || 0, alignment: alignment, protection: protection, applyFill: !fill.nil?, applyFont: !font.nil?, applyNumberFormat: !numFmt.nil?, applyBorder: !border.nil?, applyAlignment: !alignment.nil?, applyProtection: !protection.nil?
+ end
if options[:type] == :xf
xf_index = (cellXfs << style)
@@ -330,7 +330,7 @@ module Axlsx
options[key.to_sym] = value unless options.key?(key.to_sym)
end
font = Font.new(options)
- font.color = Color.new(:rgb => options[:fg_color]) if options[:fg_color]
+ font.color = Color.new(rgb: options[:fg_color]) if options[:fg_color]
font.name = options[:font_name] if options[:font_name]
options[:type] == :dxf ? font : fonts << font
end
@@ -342,7 +342,7 @@ module Axlsx
def parse_fill_options(options = {})
return unless options[:bg_color]
- color = Color.new(:rgb => options[:bg_color])
+ color = Color.new(rgb: options[:bg_color])
dxf = options[:type] == :dxf
color_key = dxf ? :bgColor : :fgColor
pattern = PatternFill.new(:patternType => :solid, color_key => color)
@@ -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
}
@@ -390,24 +390,22 @@ module Axlsx
if options[:border].nil?
base_border_opts = {}
- else
- if options[:border].is_a?(Array)
- borders_array += options[:border]
+ elsif options[:border].is_a?(Array)
+ borders_array += options[:border]
- base_border_opts = {}
+ base_border_opts = {}
- options[:border].each do |b_opts|
- if b_opts[:edges].nil?
- base_border_opts = base_border_opts.merge(b_opts)
- end
+ options[:border].each do |b_opts|
+ if b_opts[:edges].nil?
+ base_border_opts = base_border_opts.merge(b_opts)
end
- else
- borders_array << options[:border]
+ end
+ else
+ borders_array << options[:border]
- base_border_opts = options[:border]
+ base_border_opts = options[:border]
- validate_border_hash.call(base_border_opts)
- end
+ validate_border_hash.call(base_border_opts)
end
Border::EDGES.each do |edge|
@@ -441,15 +439,15 @@ 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
border.prs << BorderPr.new({
- :name => edge,
- :style => edge_b_opts[:style],
- :color => Color.new(:rgb => edge_b_opts[:color])
+ name: edge,
+ style: edge_b_opts[:style],
+ color: Color.new(rgb: edge_b_opts[:color])
})
end
end
@@ -472,8 +470,8 @@ module Axlsx
# When the type is :dxf we always need to create a new numFmt object
if options[:format_code] || options[:type] == :dxf
# If this is a standard xf we pull from numFmts the highest current and increment for num_fmt
- options[:num_fmt] ||= (@numFmts.map { |num_fmt| num_fmt.numFmtId }.max + 1) if options[:type] != :dxf
- numFmt = NumFmt.new(:numFmtId => options[:num_fmt] || 0, :formatCode => options[:format_code].to_s)
+ options[:num_fmt] ||= (@numFmts.map(&:numFmtId).max + 1) if options[:type] != :dxf
+ numFmt = NumFmt.new(numFmtId: options[:num_fmt] || 0, formatCode: options[:format_code].to_s)
options[:type] == :dxf ? numFmt : (numFmts << numFmt; numFmt.numFmtId)
else
options[:num_fmt]
@@ -498,46 +496,46 @@ module Axlsx
# Axlsx::STYLE_THIN_BORDER
def load_default_styles
@numFmts = SimpleTypedList.new NumFmt, 'numFmts'
- @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDD, :formatCode => "yyyy/mm/dd")
- @numFmts << NumFmt.new(:numFmtId => NUM_FMT_YYYYMMDDHHMMSS, :formatCode => "yyyy/mm/dd hh:mm:ss")
+ @numFmts << NumFmt.new(numFmtId: NUM_FMT_YYYYMMDD, formatCode: "yyyy/mm/dd")
+ @numFmts << NumFmt.new(numFmtId: NUM_FMT_YYYYMMDDHHMMSS, formatCode: "yyyy/mm/dd hh:mm:ss")
@numFmts.lock
@fonts = SimpleTypedList.new Font, 'fonts'
- @fonts << Font.new(:name => "Arial", :sz => 11, :family => 1)
+ @fonts << Font.new(name: "Arial", sz: 11, family: 1)
@fonts.lock
@fills = SimpleTypedList.new Fill, 'fills'
- @fills << Fill.new(Axlsx::PatternFill.new(:patternType => :none))
- @fills << Fill.new(Axlsx::PatternFill.new(:patternType => :gray125))
+ @fills << Fill.new(Axlsx::PatternFill.new(patternType: :none))
+ @fills << Fill.new(Axlsx::PatternFill.new(patternType: :gray125))
@fills.lock
@borders = SimpleTypedList.new Border, 'borders'
@borders << Border.new
black_border = Border.new
[:left, :right, :top, :bottom].each do |item|
- black_border.prs << BorderPr.new(:name => item, :style => :thin, :color => Color.new(:rgb => "FF000000"))
+ black_border.prs << BorderPr.new(name: item, style: :thin, color: Color.new(rgb: "FF000000"))
end
@borders << black_border
@borders.lock
@cellStyleXfs = SimpleTypedList.new Xf, "cellStyleXfs"
- @cellStyleXfs << Xf.new(:borderId => 0, :numFmtId => 0, :fontId => 0, :fillId => 0)
+ @cellStyleXfs << Xf.new(borderId: 0, numFmtId: 0, fontId: 0, fillId: 0)
@cellStyleXfs.lock
@cellStyles = SimpleTypedList.new CellStyle, 'cellStyles'
- @cellStyles << CellStyle.new(:name => "Normal", :builtinId => 0, :xfId => 0)
+ @cellStyles << CellStyle.new(name: "Normal", builtinId: 0, xfId: 0)
@cellStyles.lock
@cellXfs = SimpleTypedList.new Xf, "cellXfs"
- @cellXfs << Xf.new(:borderId => 0, :xfId => 0, :numFmtId => 0, :fontId => 0, :fillId => 0)
- @cellXfs << Xf.new(:borderId => 1, :xfId => 0, :numFmtId => 0, :fontId => 0, :fillId => 0)
+ @cellXfs << Xf.new(borderId: 0, xfId: 0, numFmtId: 0, fontId: 0, fillId: 0)
+ @cellXfs << Xf.new(borderId: 1, xfId: 0, numFmtId: 0, fontId: 0, fillId: 0)
# default date formatting
- @cellXfs << Xf.new(:borderId => 0, :xfId => 0, :numFmtId => 14, :fontId => 0, :fillId => 0, :applyNumberFormat => 1)
+ @cellXfs << Xf.new(borderId: 0, xfId: 0, numFmtId: 14, fontId: 0, fillId: 0, applyNumberFormat: 1)
@cellXfs.lock
@dxfs = SimpleTypedList.new(Dxf, "dxfs"); @dxfs.lock
- @tableStyles = TableStyles.new(:defaultTableStyle => "TableStyleMedium9", :defaultPivotStyle => "PivotStyleLight16"); @tableStyles.lock
+ @tableStyles = TableStyles.new(defaultTableStyle: "TableStyleMedium9", defaultPivotStyle: "PivotStyleLight16"); @tableStyles.lock
end
end
end
diff --git a/lib/axlsx/stylesheet/table_style.rb b/lib/axlsx/stylesheet/table_style.rb
index 4423c518..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 49f6e601..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 459e0099..70951eb8 100644
--- a/lib/axlsx/util/constants.rb
+++ b/lib/axlsx/util/constants.rb
@@ -239,25 +239,25 @@ module Axlsx
COMMENT_PN = "comments%d.xml"
# location of schema files for validation
- SCHEMA_BASE = (File.dirname(__FILE__) + '/../../schema/').freeze
+ SCHEMA_BASE = "#{File.dirname(__FILE__)}/../../schema/"
# App validation schema
- APP_XSD = (SCHEMA_BASE + "shared-documentPropertiesExtended.xsd").freeze
+ APP_XSD = "#{SCHEMA_BASE}shared-documentPropertiesExtended.xsd"
# core validation schema
- CORE_XSD = (SCHEMA_BASE + "opc-coreProperties.xsd").freeze
+ CORE_XSD = "#{SCHEMA_BASE}opc-coreProperties.xsd"
# content types validation schema
- CONTENT_TYPES_XSD = (SCHEMA_BASE + "opc-contentTypes.xsd").freeze
+ CONTENT_TYPES_XSD = "#{SCHEMA_BASE}opc-contentTypes.xsd"
# rels validation schema
- RELS_XSD = (SCHEMA_BASE + "opc-relationships.xsd").freeze
+ RELS_XSD = "#{SCHEMA_BASE}opc-relationships.xsd"
# spreadsheetML validation schema
- SML_XSD = (SCHEMA_BASE + "sml.xsd").freeze
+ SML_XSD = "#{SCHEMA_BASE}sml.xsd"
# drawing validation schema
- DRAWING_XSD = (SCHEMA_BASE + "dml-spreadsheetDrawing.xsd").freeze
+ DRAWING_XSD = "#{SCHEMA_BASE}dml-spreadsheetDrawing.xsd"
# number format id for pecentage formatting using the default formatting id.
NUM_FMT_PERCENT = 9
@@ -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/simple_typed_list.rb b/lib/axlsx/util/simple_typed_list.rb
index c3910fca..30cfd2a5 100644
--- a/lib/axlsx/util/simple_typed_list.rb
+++ b/lib/axlsx/util/simple_typed_list.rb
@@ -15,6 +15,12 @@ module Axlsx
undef_method name
end
+ # We often call index(element) on instances of SimpleTypedList. Thus, we do not want to inherit Array
+ # implementation of == / eql? which walks the elements calling == / eql?. Instead we want the fast
+ # and original versions from BasicObject.
+ alias :== :equal?
+ alias :eql? :equal?
+
# Creats a new typed list
# @param [Array, Class] type An array of Class objects or a single Class object
# @param [String] serialize_as The tag name to use in serialization
@@ -85,12 +91,12 @@ module Axlsx
end
# join operator
- # @param [Array] v the array to join
+ # @param [Array] other the array to join
# @raise [ArgumentError] if any of the values being joined are not
# one of the allowed types
# @return [SimpleTypedList]
- def +(v)
- v.each do |item|
+ def +(other)
+ other.each do |item|
self << item
end
super
diff --git a/lib/axlsx/util/storage.rb b/lib/axlsx/util/storage.rb
index 1e12b2d4..ac5e9ebc 100644
--- a/lib/axlsx/util/storage.rb
+++ b/lib/axlsx/util/storage.rb
@@ -9,9 +9,9 @@ module Axlsx
# storage types
TYPES = {
- :root => 5,
- :stream => 2,
- :storage => 1
+ root: 5,
+ stream: 2,
+ storage: 1
}.freeze
# Creates a byte string for this storage
@@ -33,9 +33,9 @@ module Axlsx
# storage colors
COLORS = {
- :red => 0,
- :black => 1
- }
+ red: 0,
+ black: 1
+ }.freeze
# The color of this node in the directory tree. Defaults to black if not specified
# @return [Integer] color
@@ -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 95d3e4a7..5f6dcff7 100644
--- a/lib/axlsx/workbook/workbook.rb
+++ b/lib/axlsx/workbook/workbook.rb
@@ -1,41 +1,41 @@
# frozen_string_literal: true
module Axlsx
- require 'axlsx/workbook/worksheet/sheet_calc_pr.rb'
- require 'axlsx/workbook/worksheet/auto_filter/auto_filter.rb'
- require 'axlsx/workbook/worksheet/date_time_converter.rb'
- require 'axlsx/workbook/worksheet/protected_range.rb'
- require 'axlsx/workbook/worksheet/protected_ranges.rb'
+ require 'axlsx/workbook/worksheet/sheet_calc_pr'
+ require 'axlsx/workbook/worksheet/auto_filter/auto_filter'
+ require 'axlsx/workbook/worksheet/date_time_converter'
+ require 'axlsx/workbook/worksheet/protected_range'
+ require 'axlsx/workbook/worksheet/protected_ranges'
require 'axlsx/workbook/worksheet/rich_text_run'
require 'axlsx/workbook/worksheet/rich_text'
- require 'axlsx/workbook/worksheet/cell_serializer.rb'
- require 'axlsx/workbook/worksheet/cell.rb'
- require 'axlsx/workbook/worksheet/page_margins.rb'
- require 'axlsx/workbook/worksheet/page_set_up_pr.rb'
- require 'axlsx/workbook/worksheet/outline_pr.rb'
- require 'axlsx/workbook/worksheet/page_setup.rb'
- require 'axlsx/workbook/worksheet/header_footer.rb'
- require 'axlsx/workbook/worksheet/print_options.rb'
- require 'axlsx/workbook/worksheet/cfvo.rb'
- require 'axlsx/workbook/worksheet/cfvos.rb'
- require 'axlsx/workbook/worksheet/color_scale.rb'
- require 'axlsx/workbook/worksheet/data_bar.rb'
- require 'axlsx/workbook/worksheet/icon_set.rb'
- require 'axlsx/workbook/worksheet/conditional_formatting.rb'
- require 'axlsx/workbook/worksheet/conditional_formatting_rule.rb'
- require 'axlsx/workbook/worksheet/conditional_formattings.rb'
- require 'axlsx/workbook/worksheet/row.rb'
- require 'axlsx/workbook/worksheet/col.rb'
- require 'axlsx/workbook/worksheet/cols.rb'
- require 'axlsx/workbook/worksheet/comments.rb'
- require 'axlsx/workbook/worksheet/comment.rb'
- require 'axlsx/workbook/worksheet/merged_cells.rb'
- require 'axlsx/workbook/worksheet/sheet_protection.rb'
- require 'axlsx/workbook/worksheet/sheet_pr.rb'
- require 'axlsx/workbook/worksheet/dimension.rb'
- require 'axlsx/workbook/worksheet/sheet_data.rb'
- require 'axlsx/workbook/worksheet/worksheet_drawing.rb'
- require 'axlsx/workbook/worksheet/worksheet_comments.rb'
+ require 'axlsx/workbook/worksheet/cell_serializer'
+ require 'axlsx/workbook/worksheet/cell'
+ require 'axlsx/workbook/worksheet/page_margins'
+ require 'axlsx/workbook/worksheet/page_set_up_pr'
+ require 'axlsx/workbook/worksheet/outline_pr'
+ require 'axlsx/workbook/worksheet/page_setup'
+ require 'axlsx/workbook/worksheet/header_footer'
+ require 'axlsx/workbook/worksheet/print_options'
+ require 'axlsx/workbook/worksheet/cfvo'
+ require 'axlsx/workbook/worksheet/cfvos'
+ require 'axlsx/workbook/worksheet/color_scale'
+ require 'axlsx/workbook/worksheet/data_bar'
+ require 'axlsx/workbook/worksheet/icon_set'
+ require 'axlsx/workbook/worksheet/conditional_formatting'
+ require 'axlsx/workbook/worksheet/conditional_formatting_rule'
+ require 'axlsx/workbook/worksheet/conditional_formattings'
+ require 'axlsx/workbook/worksheet/row'
+ require 'axlsx/workbook/worksheet/col'
+ require 'axlsx/workbook/worksheet/cols'
+ require 'axlsx/workbook/worksheet/comments'
+ require 'axlsx/workbook/worksheet/comment'
+ require 'axlsx/workbook/worksheet/merged_cells'
+ require 'axlsx/workbook/worksheet/sheet_protection'
+ require 'axlsx/workbook/worksheet/sheet_pr'
+ require 'axlsx/workbook/worksheet/dimension'
+ require 'axlsx/workbook/worksheet/sheet_data'
+ require 'axlsx/workbook/worksheet/worksheet_drawing'
+ require 'axlsx/workbook/worksheet/worksheet_comments'
require 'axlsx/workbook/worksheet/worksheet_hyperlink'
require 'axlsx/workbook/worksheet/worksheet_hyperlinks'
require 'axlsx/workbook/worksheet/break'
@@ -43,22 +43,22 @@ module Axlsx
require 'axlsx/workbook/worksheet/col_breaks'
require 'axlsx/workbook/workbook_view'
require 'axlsx/workbook/workbook_views'
- require 'axlsx/workbook/worksheet/worksheet.rb'
- require 'axlsx/workbook/shared_strings_table.rb'
- require 'axlsx/workbook/defined_name.rb'
- require 'axlsx/workbook/defined_names.rb'
- require 'axlsx/workbook/worksheet/table_style_info.rb'
- require 'axlsx/workbook/worksheet/table.rb'
- require 'axlsx/workbook/worksheet/tables.rb'
- require 'axlsx/workbook/worksheet/pivot_table_cache_definition.rb'
- require 'axlsx/workbook/worksheet/pivot_table.rb'
- require 'axlsx/workbook/worksheet/pivot_tables.rb'
- require 'axlsx/workbook/worksheet/data_validation.rb'
- require 'axlsx/workbook/worksheet/data_validations.rb'
- require 'axlsx/workbook/worksheet/sheet_view.rb'
- require 'axlsx/workbook/worksheet/sheet_format_pr.rb'
- require 'axlsx/workbook/worksheet/pane.rb'
- require 'axlsx/workbook/worksheet/selection.rb'
+ require 'axlsx/workbook/worksheet/worksheet'
+ require 'axlsx/workbook/shared_strings_table'
+ require 'axlsx/workbook/defined_name'
+ require 'axlsx/workbook/defined_names'
+ require 'axlsx/workbook/worksheet/table_style_info'
+ require 'axlsx/workbook/worksheet/table'
+ require 'axlsx/workbook/worksheet/tables'
+ require 'axlsx/workbook/worksheet/pivot_table_cache_definition'
+ require 'axlsx/workbook/worksheet/pivot_table'
+ require 'axlsx/workbook/worksheet/pivot_tables'
+ require 'axlsx/workbook/worksheet/data_validation'
+ require 'axlsx/workbook/worksheet/data_validations'
+ require 'axlsx/workbook/worksheet/sheet_view'
+ require 'axlsx/workbook/worksheet/sheet_format_pr'
+ require 'axlsx/workbook/worksheet/pane'
+ require 'axlsx/workbook/worksheet/selection'
# The Workbook class is an xlsx workbook that manages worksheets, charts, drawings and styles.
# The following parts of the Office Open XML spreadsheet specification are not implimented in this version.
@@ -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
@@ -171,7 +171,7 @@ module Axlsx
# @see Comment
# @return [Comments]
def comments
- worksheets.map { |sheet| sheet.comments }.compact
+ worksheets.map(&:comments).compact
end
# The styles associated with this workbook
@@ -197,16 +197,16 @@ 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]
- if current_style
- new_style = Axlsx.hash_deep_merge(current_style, cell.raw_style)
- else
- new_style = cell.raw_style
- end
+ new_style = if current_style
+ Axlsx.hash_deep_merge(current_style, cell.raw_style)
+ else
+ cell.raw_style
+ end
cell.style = styles.add_style(new_style)
end
@@ -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
@@ -369,7 +369,7 @@ module Axlsx
# generates a shared string object against all cells in all worksheets.
# @return [SharedStringTable]
def shared_strings
- SharedStringsTable.new(worksheets.collect { |ws| ws.cells }, xml_space)
+ SharedStringsTable.new(worksheets.collect(&:cells), xml_space)
end
# The xml:space attribute for the worksheet.
@@ -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 5a74d79a..586dc711 100644
--- a/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb
+++ b/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
-require 'axlsx/workbook/worksheet/auto_filter/filter_column.rb'
-require 'axlsx/workbook/worksheet/auto_filter/filters.rb'
+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/filter_column.rb b/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb
index 16096a52..e5c3ef77 100644
--- a/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb
+++ b/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb
@@ -28,7 +28,7 @@ module Axlsx
serializable_attributes :col_id, :hidden_button, :show_button
# Allowed filters
- FILTERS = [:filters] # , :top10, :custom_filters, :dynamic_filters, :color_filters, :icon_filters]
+ FILTERS = [:filters].freeze # , :top10, :custom_filters, :dynamic_filters, :color_filters, :icon_filters]
# Zero-based index indicating the AutoFilter column to which this filter information applies.
# @return [Integer]
diff --git a/lib/axlsx/workbook/worksheet/auto_filter/filters.rb b/lib/axlsx/workbook/worksheet/auto_filter/filters.rb
index 38bafe85..95e1b885 100644
--- a/lib/axlsx/workbook/worksheet/auto_filter/filters.rb
+++ b/lib/axlsx/workbook/worksheet/auto_filter/filters.rb
@@ -24,7 +24,7 @@ module Axlsx
serializable_attributes :blank, :calendar_type
# Allowed calendar types
- CALENDAR_TYPES = %w(gregorian gregorianUs gregorianMeFrench gregorianArabic hijri hebrew taiwan japan thai korea saka gregorianXlitEnglish gregorianXlitFrench none)
+ CALENDAR_TYPES = %w(gregorian gregorianUs gregorianMeFrench gregorianArabic hijri hebrew taiwan japan thai korea saka gregorianXlitEnglish gregorianXlitFrench none).freeze
# Flag indicating whether to filter by blank.
# @return [Boolean]
@@ -157,7 +157,7 @@ module Axlsx
serializable_attributes :date_time_grouping, :year, :month, :day, :hour, :minute, :second
# Allowed date time groupings
- DATE_TIME_GROUPING = %w(year month day hour minute second)
+ DATE_TIME_GROUPING = %w(year month day hour minute second).freeze
# Grouping level
# This must be one of year, month, day, hour, minute or second.
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 09cf2064..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?
@@ -73,6 +72,9 @@ module Axlsx
CELL_TYPES = [:date, :time, :float, :integer, :richtext,
:string, :boolean, :iso_8601, :text].freeze
+ # A regular expression to match the alpha(column)numeric(row) reference of a cell
+ CELL_REFERENCE_REGEX = /([A-Z]+)([0-9]+)/.freeze
+
# The index of the cellXfs item to be applied to this cell.
# @return [Integer]
# @see Axlsx::Styles
@@ -164,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
@@ -174,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
@@ -296,7 +298,7 @@ module Axlsx
# @param [String] v The 8 character representation for an rgb color #FFFFFFFF"
def color=(v)
- @color = v.is_a?(Color) ? v : Color.new(:rgb => v)
+ @color = v.is_a?(Color) ? v : Color.new(rgb: v)
@is_text_run = true
end
@@ -342,20 +344,20 @@ 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 sell.
+ # @return [String] The absolute alpha(column)numeric(row) reference for this cell.
# @example Absolute Cell Reference
# ws.rows.first.cells.first.r #=> "$A$1"
def r_abs
- "$#{r.match(/([A-Z]+)([0-9]+)/)[1, 2].join('$')}"
+ "$#{CELL_REFERENCE_REGEX.match(r)[1, 2].join('$')}"
end
# @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
@@ -372,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
@@ -388,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 &&
@@ -423,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
@@ -439,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
@@ -479,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
@@ -522,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/col.rb b/lib/axlsx/workbook/worksheet/col.rb
index ff942d32..38ac7454 100644
--- a/lib/axlsx/workbook/worksheet/col.rb
+++ b/lib/axlsx/workbook/worksheet/col.rb
@@ -88,7 +88,7 @@ module Axlsx
# @see Col#outline
def outline_level=(v)
Axlsx.validate_unsigned_numeric(v)
- raise ArgumentError, 'outlineLevel must be between 0 and 7' unless 0 <= v && v <= 7
+ raise ArgumentError, 'outlineLevel must be between 0 and 7' unless v >= 0 && v <= 7
@outline_level = v
end
diff --git a/lib/axlsx/workbook/worksheet/col_breaks.rb b/lib/axlsx/workbook/worksheet/col_breaks.rb
index 58fe9e10..cc7d6abb 100644
--- a/lib/axlsx/workbook/worksheet/col_breaks.rb
+++ b/lib/axlsx/workbook/worksheet/col_breaks.rb
@@ -16,7 +16,7 @@ module Axlsx
# Break will be passed to the created break object.
# @see Break
def add_break(options)
- self << Break.new(options.merge(:max => 1048575, :man => true))
+ self << Break.new(options.merge(max: 1048575, man: true))
last
end
diff --git a/lib/axlsx/workbook/worksheet/color_scale.rb b/lib/axlsx/workbook/worksheet/color_scale.rb
index fb84668b..84ece25b 100644
--- a/lib/axlsx/workbook/worksheet/color_scale.rb
+++ b/lib/axlsx/workbook/worksheet/color_scale.rb
@@ -12,8 +12,8 @@ module Axlsx
# These are the default conditional formatting value objects
# that define a two tone color gradient.
def default_cfvos
- [{ :type => :min, :val => 0, :color => 'FFFF7128' },
- { :type => :max, :val => 0, :color => 'FFFFEF9C' }]
+ [{ type: :min, val: 0, color: 'FFFF7128' },
+ { type: :max, val: 0, color: 'FFFFEF9C' }]
end
# A builder for two tone color gradient
@@ -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
@@ -68,9 +68,9 @@ module Axlsx
# @option [Any] val The value of the cfvo to add
# @option [String] The rgb color for the cfvo
def add(options = {})
- value_objects << Cfvo.new(:type => options[:type] || :min, :val => options[:val] || 0)
- colors << Color.new(:rgb => options[:color] || "FF000000")
- { :cfvo => value_objects.last, :color => colors.last }
+ value_objects << Cfvo.new(type: options[:type] || :min, val: options[:val] || 0)
+ colors << Color.new(rgb: options[:color] || "FF000000")
+ { cfvo: value_objects.last, color: colors.last }
end
# removes the cfvo and color pair at the index specified.
diff --git a/lib/axlsx/workbook/worksheet/comment.rb b/lib/axlsx/workbook/worksheet/comment.rb
index ea8324d0..4275cf8e 100644
--- a/lib/axlsx/workbook/worksheet/comment.rb
+++ b/lib/axlsx/workbook/worksheet/comment.rb
@@ -80,8 +80,8 @@ 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)
- @vml_shape = VmlShape.new(:row => pos[1], :column => pos[0], :visible => @visible) do |vml|
+ 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
vml.top_row = vml.row
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 482bd029..95e54742 100644
--- a/lib/axlsx/workbook/worksheet/data_bar.rb
+++ b/lib/axlsx/workbook/worksheet/data_bar.rb
@@ -14,8 +14,8 @@ module Axlsx
class << self
# This differs from ColorScale. There must be exactly two cfvos one color
def default_cfvos
- [{ :type => :min, :val => "0" },
- { :type => :max, :val => "0" }]
+ [{ type: :min, val: "0" },
+ { type: :max, val: "0" }]
end
end
@@ -38,7 +38,7 @@ module Axlsx
serializable_attributes :min_length, :max_length, :show_value
# instance values that must be serialized as their own elements - e.g. not attributes.
- CHILD_ELEMENTS = [:value_objects, :color]
+ CHILD_ELEMENTS = [:value_objects, :color].freeze
# minLength attribute
# The minimum length of the data bar, as a percentage of the cell width.
@@ -72,7 +72,7 @@ module Axlsx
# the color object used in the data bar formatting
# @return [Color]
def color
- @color ||= Color.new :rgb => "FF0000FF"
+ @color ||= Color.new rgb: "FF0000FF"
end
# @see minLength
@@ -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
@@ -117,11 +117,11 @@ module Axlsx
def initialize_cfvos(cfvos)
self.class.default_cfvos.each_with_index.map do |default, index|
- if index < cfvos.size
- value_objects << Cfvo.new(default.merge(cfvos[index]))
- else
- value_objects << Cfvo.new(default)
- end
+ value_objects << if index < cfvos.size
+ Cfvo.new(default.merge(cfvos[index]))
+ else
+ Cfvo.new(default)
+ end
end
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/dimension.rb b/lib/axlsx/workbook/worksheet/dimension.rb
index 42e02e72..f27404b6 100644
--- a/lib/axlsx/workbook/worksheet/dimension.rb
+++ b/lib/axlsx/workbook/worksheet/dimension.rb
@@ -39,7 +39,7 @@ module Axlsx
def to_xml_string(str = +'')
return if worksheet.rows.empty?
- str << "<dimension ref=\"%s\"></dimension>" % sqref
+ str << '<dimension ref="' << sqref << '"></dimension>'
end
# The first cell in the dimension
diff --git a/lib/axlsx/workbook/worksheet/icon_set.rb b/lib/axlsx/workbook/worksheet/icon_set.rb
index c4b5f2ff..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
@@ -75,7 +75,7 @@ module Axlsx
# I am keeping this private for now as I am not sure what impact changes to the required two cfvo objects will do.
def initialize_value_objects
@value_objects = SimpleTypedList.new Cfvo
- @value_objects.concat [Cfvo.new(:type => :percent, :val => 0), Cfvo.new(:type => :percent, :val => 33), Cfvo.new(:type => :percent, :val => 67)]
+ @value_objects.concat [Cfvo.new(type: :percent, val: 0), Cfvo.new(type: :percent, val: 33), Cfvo.new(type: :percent, val: 67)]
@value_objects.lock
end
end
diff --git a/lib/axlsx/workbook/worksheet/merged_cells.rb b/lib/axlsx/workbook/worksheet/merged_cells.rb
index c0ca1ebe..90e1bfcb 100644
--- a/lib/axlsx/workbook/worksheet/merged_cells.rb
+++ b/lib/axlsx/workbook/worksheet/merged_cells.rb
@@ -12,16 +12,14 @@ module Axlsx
end
# adds cells to the merged cells collection
- # @param [Array||String] cells The cells to add to the merged cells
+ # @param [Array|String] cells The cells to add to the merged cells
# collection. This can be an array of actual cells or a string style
# range like 'A1:C1'
def add(cells)
self << if cells.is_a?(String)
cells
elsif cells.is_a?(Array)
- Axlsx::cell_range(cells, false)
- elsif cells.is_a?(Row)
- 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 44a50f19..afad9483 100644
--- a/lib/axlsx/workbook/worksheet/pivot_table.rb
+++ b/lib/axlsx/workbook/worksheet/pivot_table.rb
@@ -124,7 +124,7 @@ module Axlsx
@data = []
v.each do |data_field|
if data_field.is_a? String
- data_field = { :ref => data_field }
+ data_field = { ref: data_field }
end
data_field.each do |key, value|
if key == :num_fmt
@@ -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 f8ce82c5..3e712cb5 100644
--- a/lib/axlsx/workbook/worksheet/protected_ranges.rb
+++ b/lib/axlsx/workbook/worksheet/protected_ranges.rb
@@ -19,9 +19,9 @@ 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}")
+ self << ProtectedRange.new(sqref: sqref, name: "Range#{size}")
last
end
diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb
index ffd2f941..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
@@ -140,7 +140,7 @@ module Axlsx
# @param [String] v The 8 character representation for an rgb color #FFFFFFFF"
def color=(v)
- @color = v.is_a?(Color) ? v : Color.new(:rgb => v)
+ @color = v.is_a?(Color) ? v : Color.new(rgb: v)
end
# The inline sz property for the cell
@@ -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,20 +208,20 @@ 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.keys.each do |key|
+ data.each do |key, val|
case key
when :font_name
str << '<rFont val="' << font_name << '"/>'
when :color
- str << data[key].to_xml_string
+ str << val.to_xml_string
else
- str << '<' << key.to_s << ' val="' << xml_value(data[key]) << '"/>'
+ 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 dc0320b7..86d38616 100644
--- a/lib/axlsx/workbook/worksheet/row.rb
+++ b/lib/axlsx/workbook/worksheet/row.rb
@@ -89,7 +89,7 @@ module Axlsx
# @param [String] str The string this rows xml will be appended to.
# @return [String]
def to_xml_string(r_index, str = +'')
- serialized_tag('row', str, :r => Axlsx.row_ref(r_index)) do
+ serialized_tag('row', str, r: Axlsx.row_ref(r_index)) do
each_with_index { |cell, c_index| cell.to_xml_string(r_index, c_index, str) }
end
end
@@ -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 21691f7a..98409ab4 100644
--- a/lib/axlsx/workbook/worksheet/row_breaks.rb
+++ b/lib/axlsx/workbook/worksheet/row_breaks.rb
@@ -14,7 +14,7 @@ module Axlsx
# @see Break
def add_break(options)
# force feed the Excel default
- self << Break.new(options.merge(:max => 16383, :man => true))
+ self << Break.new(options.merge(max: 16383, man: true))
last
end
@@ -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_pr.rb b/lib/axlsx/workbook/worksheet/sheet_pr.rb
index ea191fa0..0676170e 100644
--- a/lib/axlsx/workbook/worksheet/sheet_pr.rb
+++ b/lib/axlsx/workbook/worksheet/sheet_pr.rb
@@ -75,7 +75,7 @@ module Axlsx
# @see tab_color
def tab_color=(v)
- @tab_color = Color.new(:rgb => v)
+ @tab_color = Color.new(rgb: v)
end
private
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 73e7533e..02e20b33 100644
--- a/lib/axlsx/workbook/worksheet/sheet_view.rb
+++ b/lib/axlsx/workbook/worksheet/sheet_view.rb
@@ -50,7 +50,7 @@ module Axlsx
:view, :top_left_cell, :color_id, :zoom_scale
# instance values that must be serialized as their own elements - e.g. not attributes.
- CHILD_ELEMENTS = [:pane, :selections]
+ CHILD_ELEMENTS = [:pane, :selections].freeze
# The pane object for the sheet view
# @return [Pane]
@@ -158,36 +158,36 @@ module Axlsx
# param [Hash] options
# return [Selection]
def add_selection(pane, options = {})
- @selections[pane] = Selection.new(options.merge(:pane => pane))
+ @selections[pane] = Selection.new(options.merge(pane: pane))
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 8c6e53b4..081f50d8 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -45,7 +45,7 @@ module Axlsx
# The name of the worksheet
# @return [String]
def name
- @name ||= "Sheet" + (index + 1).to_s
+ @name ||= "Sheet#{index + 1}"
end
# Whether to treat values starting with an equals sign as formulas or as literal strings.
@@ -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.
@@ -448,7 +448,7 @@ module Axlsx
# @see ConditionalFormattingRule#initialize
# @see file:examples/example_conditional_formatting.rb
def add_conditional_formatting(cells, rules)
- cf = ConditionalFormatting.new(:sqref => cells)
+ cf = ConditionalFormatting.new(sqref: cells)
cf.add_rules rules
conditional_formattings << cf
conditional_formattings
@@ -531,9 +531,9 @@ module Axlsx
cell.pos
end
if column_index > 0
- col_breaks.add_break(:id => column_index)
+ col_breaks.add_break(id: column_index)
end
- row_breaks.add_break(:id => row_index)
+ row_breaks.add_break(id: row_index)
end
# This is a helper method that Lets you specify a fixed width for multiple columns in a worksheet in one go.
@@ -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)
- sheet_names = @workbook.worksheets.reject { |s| s == self }.map { |s| s.name }
- raise ArgumentError, (ERR_DUPLICATE_SHEET_NAME % name) if sheet_names.include?(name)
+ name = Axlsx.coder.encode(name)
+ sheet_names = @workbook.worksheets.reject { |s| s == self }.map(&: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 c4cb8983..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
@@ -52,7 +52,7 @@ module Axlsx
def relationship
return unless @target == :external
- Relationship.new(self, HYPERLINK_R, location, :target_mode => :External)
+ Relationship.new(self, HYPERLINK_R, location, target_mode: :External)
end
# Seralize the object
@@ -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/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb b/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb
index f19630f8..334b59da 100644
--- a/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb
@@ -24,7 +24,7 @@ module Axlsx
def relationships
return [] if empty?
- map { |hyperlink| hyperlink.relationship }
+ map(&:relationship)
end
# seralize the collection of hyperlinks
diff --git a/lib/caxlsx.rb b/lib/caxlsx.rb
index e97cd68c..d2b96503 100644
--- a/lib/caxlsx.rb
+++ b/lib/caxlsx.rb
@@ -1,3 +1,3 @@
# frozen_string_literal: true
-require 'axlsx.rb'
+require 'axlsx'
diff --git a/test/benchmark.rb b/test/benchmark.rb
index d5ccdf64..fb4d7050 100755
--- a/test/benchmark.rb
+++ b/test/benchmark.rb
@@ -11,9 +11,22 @@ input1 = (32..126).to_a.pack('U*').chars.to_a # these will need to be escaped
input2 = (65..122).to_a.pack('U*').chars.to_a # these do not need to be escaped
10.times { row << input1.shuffle.join }
10.times { row << input2.shuffle.join }
-times = 3000
+times = 3_000
Benchmark.bmbm(30) do |x|
+ x.report('axlsx_merged_cells') do
+ p = Axlsx::Package.new
+ p.workbook do |wb|
+ wb.add_worksheet do |sheet|
+ times.times do
+ sheet << row
+ sheet.merge_cells(sheet.rows.last.cells)
+ end
+ end
+ end
+ p.serialize("example_axlsx_merged_cells.xlsx")
+ end
+
x.report('axlsx_noautowidth') do
p = Axlsx::Package.new
p.workbook do |wb|
@@ -85,4 +98,4 @@ Benchmark.bmbm(30) do |x|
end
end
end
-File.delete("example.csv", "example_streamed.xlsx", "example_shared.xlsx", "example_autowidth.xlsx", "example_noautowidth.xlsx", "example_zip_command.xlsx")
+File.delete("example_axlsx_merged_cells.xlsx", "example.csv", "example_streamed.xlsx", "example_shared.xlsx", "example_autowidth.xlsx", "example_noautowidth.xlsx", "example_zip_command.xlsx")
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/doc_props/tc_app.rb b/test/doc_props/tc_app.rb
index 82e33f12..c066373c 100644
--- a/test/doc_props/tc_app.rb
+++ b/test/doc_props/tc_app.rb
@@ -41,6 +41,6 @@ class TestApp < Test::Unit::TestCase
errors << error
end
- assert_equal(0, errors.size, "app.xml invalid" + errors.map(&:message).to_s)
+ assert_equal(0, errors.size, "app.xml invalid#{errors.map(&:message)}")
end
end
diff --git a/test/doc_props/tc_core.rb b/test/doc_props/tc_core.rb
index bfacab45..5a04a615 100644
--- a/test/doc_props/tc_core.rb
+++ b/test/doc_props/tc_core.rb
@@ -18,7 +18,7 @@ class TestCore < Test::Unit::TestCase
errors << error
end
- assert_equal(0, errors.size, "core.xml Invalid" + errors.map(&:message).to_s)
+ assert_equal(0, errors.size, "core.xml Invalid#{errors.map(&:message)}")
end
def test_populates_created
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_drawing.rb b/test/drawing/tc_drawing.rb
index d7e3e8df..d48ae604 100644
--- a/test/drawing/tc_drawing.rb
+++ b/test/drawing/tc_drawing.rb
@@ -26,7 +26,7 @@ class TestDrawing < Test::Unit::TestCase
end
def test_add_image
- src = File.dirname(__FILE__) + "/../fixtures/image1.jpeg"
+ src = "#{File.dirname(__FILE__)}/../fixtures/image1.jpeg"
image = @ws.add_image(image_src: src, start_at: [0, 0], width: 600, height: 400)
assert(@ws.drawing.anchors.last.is_a?(Axlsx::OneCellAnchor))
@@ -36,7 +36,7 @@ class TestDrawing < Test::Unit::TestCase
end
def test_add_two_cell_anchor_image
- src = File.dirname(__FILE__) + "/../fixtures/image1.jpeg"
+ src = "#{File.dirname(__FILE__)}/../fixtures/image1.jpeg"
image = @ws.add_image(image_src: src, start_at: [0, 0], end_at: [15, 0])
assert(@ws.drawing.anchors.last.is_a?(Axlsx::TwoCellAnchor))
diff --git a/test/drawing/tc_hyperlink.rb b/test/drawing/tc_hyperlink.rb
index c3cffb1c..5a1f5d48 100644
--- a/test/drawing/tc_hyperlink.rb
+++ b/test/drawing/tc_hyperlink.rb
@@ -6,7 +6,7 @@ class TestHyperlink < Test::Unit::TestCase
def setup
@p = Axlsx::Package.new
ws = @p.workbook.add_worksheet
- @test_img = File.dirname(__FILE__) + "/../fixtures/image1.jpeg"
+ @test_img = "#{File.dirname(__FILE__)}/../fixtures/image1.jpeg"
@image = ws.add_image image_src: @test_img, hyperlink: "http://axlsx.blogspot.com"
@hyperlink = @image.hyperlink
end
diff --git a/test/drawing/tc_one_cell_anchor.rb b/test/drawing/tc_one_cell_anchor.rb
index e3eb8d90..5015d123 100644
--- a/test/drawing/tc_one_cell_anchor.rb
+++ b/test/drawing/tc_one_cell_anchor.rb
@@ -6,7 +6,7 @@ class TestOneCellAnchor < Test::Unit::TestCase
def setup
@p = Axlsx::Package.new
@ws = @p.workbook.add_worksheet
- @test_img = File.dirname(__FILE__) + "/../fixtures/image1.jpeg"
+ @test_img = "#{File.dirname(__FILE__)}/../fixtures/image1.jpeg"
@image = @ws.add_image image_src: @test_img
@anchor = @image.anchor
end
diff --git a/test/drawing/tc_pic.rb b/test/drawing/tc_pic.rb
index dc0f32da..f4961d4c 100644
--- a/test/drawing/tc_pic.rb
+++ b/test/drawing/tc_pic.rb
@@ -9,10 +9,10 @@ class TestPic < Test::Unit::TestCase
@p = Axlsx::Package.new
ws = @p.workbook.add_worksheet
- @test_img = @test_img_jpg = File.dirname(__FILE__) + "/../fixtures/image1.jpeg"
- @test_img_png = File.dirname(__FILE__) + "/../fixtures/image1.png"
- @test_img_gif = File.dirname(__FILE__) + "/../fixtures/image1.gif"
- @test_img_fake = File.dirname(__FILE__) + "/../fixtures/image1_fake.jpg"
+ @test_img = @test_img_jpg = "#{File.dirname(__FILE__)}/../fixtures/image1.jpeg"
+ @test_img_png = "#{File.dirname(__FILE__)}/../fixtures/image1.png"
+ @test_img_gif = "#{File.dirname(__FILE__)}/../fixtures/image1.gif"
+ @test_img_fake = "#{File.dirname(__FILE__)}/../fixtures/image1_fake.jpg"
@test_img_remote_png = "https://example.com/sample-image.png"
@test_img_remote_fake = "invalid_URI"
@image = ws.add_image image_src: @test_img, hyperlink: 'https://github.com/randym', tooltip: "What's up doc?", opacity: 5
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 fc7d9d79..f990e8e2 100644
--- a/test/util/tc_mime_type_utils.rb
+++ b/test/util/tc_mime_type_utils.rb
@@ -7,18 +7,18 @@ class TestMimeTypeUtils < Test::Unit::TestCase
stub_request(:get, 'https://example.com/sample-image.png')
.to_return(body: File.new('examples/sample.png'), status: 200)
- @test_img = File.dirname(__FILE__) + "/../fixtures/image1.jpeg"
+ @test_img = "#{File.dirname(__FILE__)}/../fixtures/image1.jpeg"
@test_img_url = "https://example.com/sample-image.png"
end
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_shared_strings_table.rb b/test/workbook/tc_shared_strings_table.rb
index 2edf5f4a..4ac8b112 100644
--- a/test/workbook/tc_shared_strings_table.rb
+++ b/test/workbook/tc_shared_strings_table.rb
@@ -45,7 +45,7 @@ class TestSharedStringsTable < Test::Unit::TestCase
errors << error
end
- assert_equal(0, errors.size, "sharedStirngs.xml Invalid" + errors.map(&:message).to_s)
+ assert_equal(0, errors.size, "sharedStirngs.xml Invalid#{errors.map(&:message)}")
end
def test_remove_control_characters_in_xml_serialization
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_rich_text_run.rb b/test/workbook/worksheet/tc_rich_text_run.rb
index 6274dda8..be05d818 100644
--- a/test/workbook/worksheet/tc_rich_text_run.rb
+++ b/test/workbook/worksheet/tc_rich_text_run.rb
@@ -151,7 +151,7 @@ class RichTextRun < Test::Unit::TestCase
def test_multiline_autowidth
wrap = @p.workbook.styles.add_style({ alignment: { wrap_text: true } })
- awtr = Axlsx::RichTextRun.new('I\'m bold' + "\n", b: true)
+ awtr = Axlsx::RichTextRun.new("I'm bold\n", b: true)
rt = Axlsx::RichText.new
rt.runs << awtr
@ws.add_row [rt], style: wrap
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