<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Fabi Jordgrimsson</title>
    <description>The latest articles on DEV Community by Fabi Jordgrimsson (@fabijordgrimsson).</description>
    <link>https://dev.to/fabijordgrimsson</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3290488%2F24b934f1-65d7-4af6-91ed-96da7b5636e9.jpeg</url>
      <title>DEV Community: Fabi Jordgrimsson</title>
      <link>https://dev.to/fabijordgrimsson</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fabijordgrimsson"/>
    <language>en</language>
    <item>
      <title>🇫🇷 From "Vingt et Un" to 21: Building a Lightning-Fast French Number Parser in Ruby</title>
      <dc:creator>Fabi Jordgrimsson</dc:creator>
      <pubDate>Tue, 24 Jun 2025 10:40:13 +0000</pubDate>
      <link>https://dev.to/fabijordgrimsson/from-vingt-et-un-to-21-building-a-lightning-fast-french-number-parser-in-ruby-2hn6</link>
      <guid>https://dev.to/fabijordgrimsson/from-vingt-et-un-to-21-building-a-lightning-fast-french-number-parser-in-ruby-2hn6</guid>
      <description>&lt;p&gt;Ever tried to parse French numbers in your Ruby application?&lt;/p&gt;

&lt;p&gt;If you've worked with French text data, you know the pain: "quatre-vingt-quatorze" should become 94, "trois millions deux cent mille" should transform to 3,200,000, but good luck finding a performant solution that handles all the linguistic quirks of French numbers!&lt;/p&gt;

&lt;p&gt;That's exactly the problem I set out to solve with StringToNumber, a high-performance Ruby gem that converts French written numbers into their numeric equivalents with blazing speed and bulletproof reliability.&lt;/p&gt;

&lt;h2&gt;
  
  
  🤔 The Problem: French Numbers Are…&amp;nbsp;Complex
&lt;/h2&gt;

&lt;p&gt;French numbers aren't just "difficult", they're linguistically fascinating and computationally challenging:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Special cases: "quatre-vingts" (80) vs "quatre-vingt-un" (81)&lt;/li&gt;
&lt;li&gt;Compound forms: "soixante-dix" (literally "sixty-ten" = 70)&lt;/li&gt;
&lt;li&gt;Multiple formats: "vingt-et-un" vs "vingt et un" vs "vingt-un"&lt;/li&gt;
&lt;li&gt;Scale handling: "deux millions trois cent mille" (2,300,000)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most existing solutions either:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❌ Don't handle edge cases correctly&lt;/li&gt;
&lt;li&gt;⚠️ Have terrible performance for large datasets&lt;/li&gt;
&lt;li&gt;💔 Lack proper caching and memory management&lt;/li&gt;
&lt;li&gt;🐛 Break on complex compound numbers&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  ✨ The Solution: StringToNumber Gem
&lt;/h2&gt;

&lt;p&gt;StringToNumber tackles these challenges head-on with a dual-architecture approach:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🚀 Performance That Scales&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Up to 460x faster than naive implementations&lt;/li&gt;
&lt;li&gt;Intelligent LRU caching with thread-safe operations&lt;/li&gt;
&lt;li&gt;Pre-compiled regex patterns eliminate compilation overhead&lt;/li&gt;
&lt;li&gt;Zero-allocation matching for common cases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🎯 Comprehensive French Support&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require 'string_to_number'

# Basic numbers
StringToNumber.in_numbers('quinze') #=&amp;gt; 15
StringToNumber.in_numbers('quatre-vingts') #=&amp;gt; 80

# Complex compounds
StringToNumber.in_numbers('soixante-dix-sept') #=&amp;gt; 77
StringToNumber.in_numbers('quatre-vingt-quatorze') #=&amp;gt; 94

# Large numbers
StringToNumber.in_numbers('deux millions trois cent mille') #=&amp;gt; 2_300_000
StringToNumber.in_numbers('neuf mille neuf cent quatre-vingt-dix-neuf') #=&amp;gt; 9999
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🛡️ Production-Ready Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Thread-safe concurrent operations&lt;/li&gt;
&lt;li&gt;Input validation with helpful error messages&lt;/li&gt;
&lt;li&gt;Memory efficient with configurable cache limits&lt;/li&gt;
&lt;li&gt;Backward compatibility mode for testing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📊 Performance That Will Blow Your Mind&lt;br&gt;
Here's where StringToNumber really shines. Check out these benchmark results:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+--------+------------+----------+----------------+-------------+--------+
| Input  | Complexity | Original | StringToNumber | Improvement |        |
+--------+------------+----------+----------------+-------------+--------+
| Short  | numbers    | 0.5ms    | 0.035ms        | 14x         | faster |
| Medium | complexity | 2.1ms    | 0.045ms        | 47x         | faster |
| Long   | compounds  | 23ms     | 0.05ms         | 460x        | faster |
+--------+------------+----------+----------------+-------------+--------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# This processes 800,000+ conversions per second! 🔥
1000.times { StringToNumber.in_numbers('vingt et un') }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🎯 Real-World Use Cases&lt;/strong&gt;&lt;br&gt;
Who should use StringToNumber?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🏦 Financial apps processing French invoices/documents&lt;/li&gt;
&lt;li&gt;📊 Data pipelines cleaning French numerical text&lt;/li&gt;
&lt;li&gt;🤖 NLP projects working with French language data&lt;/li&gt;
&lt;li&gt;📱 Mobile apps supporting French localization&lt;/li&gt;
&lt;li&gt;🔍 Search engines normalizing French numerical queries&lt;/li&gt;
&lt;li&gt;&amp;nbsp;📈 Analytics platforms parsing French business data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example: Processing French Financial Data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Clean messy financial data
invoices = [
 "Montant: trois mille deux cent euros",
 "Total: quinze mille neuf cent vingt",
 "Crédit: un million deux cent mille"
]
amounts = invoices.map do |invoice|
 number_text = invoice.match(/: (.+) euros?/)&amp;amp;.[](1) || invoice.match(/: (.+)$/)&amp;amp;.[](1)
 StringToNumber.in_numbers(number_text) if number_text
end
#=&amp;gt; [3200, 15920, 1200000]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🚀 Quick Start Guide&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Installation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem install string_to_number
# or add to Gemfile
gem 'string_to_number'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Basic Usage&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require 'string_to_number'

# Convert any French number
result = StringToNumber.in_numbers('mille deux cent trente-quatre')
puts result #=&amp;gt; 1234

# Validate input before processing
if StringToNumber.valid_french_number?('vingt et un')
 puts StringToNumber.in_numbers('vingt et un') #=&amp;gt; 21
end

# Check performance stats
stats = StringToNumber.cache_stats
puts "Cache hit ratio: #{stats[:cache_hit_ratio]}"
Advanced Features
# Batch processing with automatic caching
french_numbers = ['un', 'deux', 'trois', 'vingt', 'cent']
results = french_numbers.map { |num| StringToNumber.in_numbers(num) }

# Memory management for long-running processes
StringToNumber.clear_caches! # Reset when processing new datasets

# Backward compatibility testing
old_result = StringToNumber.in_numbers('cent', use_optimized: false)
new_result = StringToNumber.in_numbers('cent', use_optimized: true)
puts old_result == new_result #=&amp;gt; true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🏗️ Under the Hood: Architecture Highlights&lt;/strong&gt;&lt;br&gt;
The gem uses a sophisticated dual-parser approach:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Optimized Parser (default): High-performance with caching&lt;/li&gt;
&lt;li&gt;Original Parser: Reference implementation for compatibility&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Key optimizations include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LRU caching with thread-safe mutex protection&lt;/li&gt;
&lt;li&gt;Instance memoization reduces initialization overhead&lt;/li&gt;
&lt;li&gt;Pre-compiled regex patterns eliminate compilation costs&lt;/li&gt;
&lt;li&gt;Intelligent word matching with zero allocations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🤝 Join the Community!&lt;/strong&gt;&lt;br&gt;
StringToNumber is just getting started, and I'd love your help making it even better!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;💡 Ways to Contribute:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⭐ Star the repo on &lt;a href="https://github.com/FabienPiette/string_to_number" rel="noopener noreferrer"&gt;https://github.com/FabienPiette/string_to_number&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🐛 Report bugs or edge cases you discover&lt;/li&gt;
&lt;li&gt;💻 Submit PRs for new features or optimizations&lt;/li&gt;
&lt;li&gt;📝 Share your use cases and success stories
📧 Let's Connect:&lt;/li&gt;
&lt;li&gt;Found an edge case? &lt;a href="https://github.com/FabienPiette/string_to_number/issues" rel="noopener noreferrer"&gt;https://github.com/FabienPiette/string_to_number/issues&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Built something cool? Tweet about it and tag me! (&lt;a href="https://bsky.app/profile/fabijordgrimsson.bsky.social" rel="noopener noreferrer"&gt;https://bsky.app/profile/fabijordgrimsson.bsky.social&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Have questions? The documentation covers common scenarios&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🎯 What's Next?&lt;/strong&gt;&lt;br&gt;
I'm actively working on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Regional variants support (Belgian/Swiss French)&lt;/li&gt;
&lt;li&gt;Decimal number parsing ("trois virgule quatorze")&lt;/li&gt;
&lt;li&gt;Ordinal numbers ("premier", "deuxième")&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Ready to supercharge your French number processing? Install StringToNumber today and transform your text processing pipeline from sluggish to lightning-fast!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gem install string_to_number&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your French data deserves better than regex soup. Give it the StringToNumber treatment! 🚀&lt;/p&gt;

&lt;p&gt;What do you think? I'd love to hear how StringToNumber works in your projects, drop me a line or star the repo if it saves you time!&lt;/p&gt;

&lt;p&gt;Happy coding! 🇫🇷💎&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>opensource</category>
      <category>nlp</category>
      <category>french</category>
    </item>
  </channel>
</rss>
