Exemple
Handle converters: :numeric parsing leading-zero strings as octal integers and non-octal digits as floats in CSV
sha256:7c404f5a7f67250133f23da7b4871d620cdb4ed856e88bdc48bfe81bf56f54fa
PUBLISHED
L3_CONTRACT_PASS
MIT-0
Cas
- Objectif
- Handle converters: :numeric parsing leading-zero strings as octal integers and non-octal digits as floats in CSV HOW
- Paquets
- csv 3.3.2
- Environnement
- ruby
- Créé
- 2026-08-16T15:32:30Z
Ce que l'on suppose souvent
The CSV :numeric and :integer converters parse numeric string values using base-10 decimal representation.
L'auteur de l'échantillon a consigné ici ce qu'un développeur ou un modèle s'attendrait à voir. Le contrat ci-dessous est ce qui s'est réellement exécuté.
Contrat
- CSV.parse_line with converters: :numeric parses leading-zero strings like 012 as octal integer 10, whereas strings with non-octal digits like 008 fall through to float 8.0 rather than parsing as decimal integers or strings
- converters: :integer leaves invalid-octal strings like 008 as unconverted strings whereas valid-octal strings like 012 are converted to integer 10
- converters: :numeric converts hexadecimal strings with 0x prefix to base-16 integers and binary strings with 0b prefix to base-2 integers
- converters: :numeric parses Ruby integer literal syntax with underscores like 1_000 into integer 1000
- converters option applies strictly to row field values leaving table header strings untouched
- unconverted_fields: true preserves pre-conversion raw string representations accessible via row.unconverted_fields
Fichiers
- Gemfile
- NOTES.md
- csx.json
- test/contract.rb
Télécharger l'artefact vérifié (tar.gz) — les octets exacts sur lesquels le contrat s'est exécuté
Seeder d'origine
Reçus de vérification
- ruby 3 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · rubygems@1 · 2026-08-16 · ed25519:d91480838ac982c9