calcsheet 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +9 -0
  3. data/CHANGELOG.md +62 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +921 -0
  6. data/lib/calcsheet/book.rb +164 -0
  7. data/lib/calcsheet/cast.rb +578 -0
  8. data/lib/calcsheet/column.rb +117 -0
  9. data/lib/calcsheet/column_letter.rb +34 -0
  10. data/lib/calcsheet/configuration.rb +186 -0
  11. data/lib/calcsheet/decimal_text.rb +19 -0
  12. data/lib/calcsheet/entry_name.rb +28 -0
  13. data/lib/calcsheet/errors.rb +186 -0
  14. data/lib/calcsheet/excel_serial.rb +65 -0
  15. data/lib/calcsheet/format_detector.rb +109 -0
  16. data/lib/calcsheet/formula_protection.rb +31 -0
  17. data/lib/calcsheet/grid.rb +20 -0
  18. data/lib/calcsheet/header_keys.rb +66 -0
  19. data/lib/calcsheet/limited_inflater.rb +326 -0
  20. data/lib/calcsheet/merge_check.rb +41 -0
  21. data/lib/calcsheet/odf.rb +45 -0
  22. data/lib/calcsheet/option_validation.rb +160 -0
  23. data/lib/calcsheet/options.rb +10 -0
  24. data/lib/calcsheet/raw_row.rb +18 -0
  25. data/lib/calcsheet/raw_types.rb +15 -0
  26. data/lib/calcsheet/readers/csv_dialect.rb +264 -0
  27. data/lib/calcsheet/readers/csv_input.rb +128 -0
  28. data/lib/calcsheet/readers/csv_reader.rb +239 -0
  29. data/lib/calcsheet/readers/ods/cell_formats.rb +115 -0
  30. data/lib/calcsheet/readers/ods/content_parser.rb +594 -0
  31. data/lib/calcsheet/readers/ods/count.rb +30 -0
  32. data/lib/calcsheet/readers/ods/cursor.rb +121 -0
  33. data/lib/calcsheet/readers/ods/patterns.rb +70 -0
  34. data/lib/calcsheet/readers/ods/row_seek.rb +157 -0
  35. data/lib/calcsheet/readers/ods/scanner.rb +302 -0
  36. data/lib/calcsheet/readers/ods/style_scan.rb +108 -0
  37. data/lib/calcsheet/readers/ods/tag_text.rb +76 -0
  38. data/lib/calcsheet/readers/ods_reader.rb +71 -0
  39. data/lib/calcsheet/readers/ox_errors.rb +40 -0
  40. data/lib/calcsheet/readers/references.rb +62 -0
  41. data/lib/calcsheet/readers/row_batches.rb +45 -0
  42. data/lib/calcsheet/readers/sax_sheet.rb +108 -0
  43. data/lib/calcsheet/readers/stream_remainder.rb +66 -0
  44. data/lib/calcsheet/readers/tag_scan.rb +119 -0
  45. data/lib/calcsheet/readers/xlsx/escapes.rb +36 -0
  46. data/lib/calcsheet/readers/xlsx/local_name.rb +54 -0
  47. data/lib/calcsheet/readers/xlsx/number_format.rb +89 -0
  48. data/lib/calcsheet/readers/xlsx/row_skipper.rb +162 -0
  49. data/lib/calcsheet/readers/xlsx/shared_strings.rb +209 -0
  50. data/lib/calcsheet/readers/xlsx/sheet_parser.rb +435 -0
  51. data/lib/calcsheet/readers/xlsx/styles.rb +156 -0
  52. data/lib/calcsheet/readers/xlsx/workbook_meta.rb +228 -0
  53. data/lib/calcsheet/readers/xlsx_reader.rb +122 -0
  54. data/lib/calcsheet/reading.rb +281 -0
  55. data/lib/calcsheet/row.rb +110 -0
  56. data/lib/calcsheet/sample.rb +10 -0
  57. data/lib/calcsheet/schema.rb +140 -0
  58. data/lib/calcsheet/sheet_info.rb +21 -0
  59. data/lib/calcsheet/sheet_names.rb +114 -0
  60. data/lib/calcsheet/sheet_selection.rb +58 -0
  61. data/lib/calcsheet/source.rb +263 -0
  62. data/lib/calcsheet/stream_body.rb +81 -0
  63. data/lib/calcsheet/time_zone.rb +96 -0
  64. data/lib/calcsheet/untrusted.rb +32 -0
  65. data/lib/calcsheet/version.rb +6 -0
  66. data/lib/calcsheet/write_book.rb +202 -0
  67. data/lib/calcsheet/write_sheet.rb +282 -0
  68. data/lib/calcsheet/writers/csv_writer.rb +138 -0
  69. data/lib/calcsheet/writers/ods_writer.rb +437 -0
  70. data/lib/calcsheet/writers/xlsx_writer.rb +350 -0
  71. data/lib/calcsheet/writers/xml_text.rb +35 -0
  72. data/lib/calcsheet/writers/zip_buffered.rb +55 -0
  73. data/lib/calcsheet/zip_container.rb +190 -0
  74. data/lib/calcsheet/zip_directory.rb +202 -0
  75. data/lib/calcsheet/zip_end_record.rb +117 -0
  76. data/lib/calcsheet.rb +295 -0
  77. metadata +200 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 79bc1c89fd78d1d3350d4018f828341811fbeb50ca15bcdf57bebf4673196d1a
4
+ data.tar.gz: a32050d33976568d5a40ba3667bc4abce2a6c5bc28b6e7dd1ea49ecc63bc7bca
5
+ SHA512:
6
+ metadata.gz: 5a2c9a9420a2f5869519ce1eaa10dd7463ab21e63ad45de2d2e948fe54af0f66bda5a9ce424e06b17b3adcf01c0bad941b8dce7a529fe486559696ee2669ccdc
7
+ data.tar.gz: 06acdf306e97bd8a9305e2b5a537e1d119a6e3c47257831abacdba9a5fe52cd752316f87e7e05b74fbf9cc5e12c1ae10b83d9400b51b7319de68b5d02a3831d5
data/.yardopts ADDED
@@ -0,0 +1,9 @@
1
+ --markup rdoc
2
+ --hide-api private
3
+ --readme README.md
4
+ --output-dir tmp/yard
5
+ --no-save
6
+ lib/**/*.rb
7
+ -
8
+ CHANGELOG.md
9
+ LICENSE.txt
data/CHANGELOG.md ADDED
@@ -0,0 +1,62 @@
1
+ # Changelog
2
+
3
+ All notable changes to this gem are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this gem adheres to
6
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-10-21
11
+
12
+ First release.
13
+
14
+ ### Added
15
+
16
+ - Read CSV, XLSX and ODS from a path or any IO, one row at a time with bounded memory: `Calcsheet.open`,
17
+ `Book#sheets`, `#sample`, `#merge_check`, `#rows`, `#each_row` and `#each_batch`. The format is detected from the
18
+ content; XLS files get a specific `UnsupportedFormatError`.
19
+ - Native types: `String`, `Integer`, `BigDecimal` from the cell text (rounded half up to 15 significant digits only
20
+ when the text is the full print of a double: a fraction or an exponent with 16 or 17 significant digits), `Date`
21
+ and `Time` decided by the number format, durations in seconds, booleans; formula cached values; `nil` with a
22
+ `:cell_error` for error cells. Option `decimals: :float`.
23
+ - Column schemas by 0-based position or by header name, with declared types (`:string`, `:integer`, `:decimal`,
24
+ `:date`, `:datetime`, `:boolean`), `required:` columns and `required_headers:`; `types: :string`.
25
+ - Row numbers as the user sees them: XLSX `r` attributes, ODS repeated rows, CSV records (plus `Row#line`).
26
+ - Merged reading of sheets with the same header (`sheet: :all`), hidden sheets excluded unless asked for;
27
+ `start_at:` resumes a read; `skip_blank:`.
28
+ - Cell errors collected per row (`on_error: :collect`) or raised (`on_error: :raise`), with sheet, row, column,
29
+ key, value and a reason code.
30
+ - CSV detection of encoding (BOM, whole-file UTF-8 check, Windows-1252), separator and quote; options `encoding:`,
31
+ `col_sep:`, `quote_char:`, `strip_formula_prefix:`. Non-seekable CSV streams are read directly with an explicit
32
+ format.
33
+ - Write CSV, XLSX and ODS to a path, any IO (non-seekable included) or a Rack body (`Calcsheet.stream`), with
34
+ typed columns, widths, decimal `scale:` (display only), bold and frozen header rows, several sheets, sheet name
35
+ validation (`sanitize_sheet_names:`) and overflow into continuation sheets `"Name (2)"` at 1,048,576 rows
36
+ (`max_rows_per_sheet:`).
37
+ - CSV writing options `col_sep:`, `row_sep:`, `bom:`, `decimal_separator:`, `date_format:`, `datetime_format:` and
38
+ the `excel_it: true` preset; formula injection protection on by default, disabled per column.
39
+ - `time_zone:` for reading and writing: UTC offsets, or any object responding to `local` (and, for writing, to
40
+ `utc_to_local` or `utc_offset`), such as `ActiveSupport::TimeZone`, without depending on ActiveSupport.
41
+ - Limits: `max_file_size`, `max_rows`, cumulative `max_uncompressed_size`, `max_compression_ratio` with
42
+ `compression_ratio_floor`, `max_zip_entries`, `max_sheets` and `max_cell_bytes`, enforced on the bytes actually
43
+ inflated; bounds on untrusted XML.
44
+ - Global configuration with `Calcsheet.configure`, every option overridable per call.
45
+ - Memory specs for large files (`bundle exec rspec --tag performance`, excluded from the default run). Each case
46
+ runs in its own process and the bound is its peak RSS. The measured throughput and memory of 1,000,000 rows are
47
+ in the [README](https://gitlab.opinioni.net/demetra-developers/rubygems/calcsheet/-/blob/main/README.md#performance).
48
+ - Every runnable (```` ```ruby ````) example of the README is run by `spec/readme_spec.rb`, which also checks the
49
+ options reference against `Configuration::DEFAULTS`.
50
+ - API documentation with YARD (`bundle exec yard`; `.yardopts` hides the `@api private` implementation).
51
+
52
+ ### Security
53
+
54
+ - Files from untrusted sources are bounded: the limits above are enforced while the bytes are inflated, not from
55
+ the sizes the archive declares, and the XML the readers buffer has fixed bounds. `max_rows` has no default; set it
56
+ when reading uploads. See the "Limits" section of the README.
57
+ - CSV written by Calcsheet is protected against formula injection by default (`formula_protection:`).
58
+ - Report vulnerabilities as described in
59
+ [SECURITY.md](https://gitlab.opinioni.net/demetra-developers/rubygems/calcsheet/-/blob/main/SECURITY.md).
60
+
61
+ [Unreleased]: https://gitlab.opinioni.net/demetra-developers/rubygems/calcsheet/-/compare/v0.1.0...develop
62
+ [0.1.0]: https://gitlab.opinioni.net/demetra-developers/rubygems/calcsheet/-/tags/v0.1.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Demetra Opinioni.net Srl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.