New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

steuer

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

steuer

bundlerRubyGems.org
Version
1.0.4
Version published
Maintainers
1
Created
Source

Steuer

A Ruby gem for German tax system utilities, including Steuernummer (tax number) conversion between different formats and validation.

Based on the official specifications from the German Wikipedia page on Steuernummer.

Features

  • Format Detection: Automatically detects the format of German tax numbers
  • Format Conversion: Convert between three different formats:
    • Standard scheme (state-specific format, e.g., 93/815/08152)
    • Unified federal scheme (12-digit, e.g., 289381508152)
    • Unified federal scheme for electronic transmission (13-digit, e.g., 2893081508152)
  • State Detection: Automatically detects the German state (Bundesland) from tax numbers
  • Validation: Validates tax numbers according to official patterns
  • Object-Oriented: Clean, object-oriented API design
  • Extensible: Designed to be extended with additional German tax utilities (VAT validation, etc.)

Installation

Add this line to your application's Gemfile:

gem 'steuer'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install steuer

Usage

Basic Usage

require 'steuer'

# Create a tax number object (auto-detects state from unambiguous formats)
tax_number = Steuer.steuernummer('93/815/08152')  # Auto-detects Baden-Württemberg

# Check if valid
puts tax_number.valid?  # => true

# Get information
puts tax_number.state_code    # => "BW"
puts tax_number.state_name    # => "Baden-Württemberg"
puts tax_number.format_type   # => :standard

# Convert between formats
puts tax_number.to_federal_12  # => "289381508152"
puts tax_number.to_federal_13  # => "2893081508152"
puts tax_number.to_standard    # => "93/815/08152"

Auto-Detection vs Explicit State

# ✅ Auto-detects from standard format (each state has unique pattern)
standard = Steuer.steuernummer('181/815/08155')  # Auto-detects Bayern
puts standard.state_code  # => "BY"

# ✅ Auto-detects from unambiguous federal prefixes
federal_12 = Steuer.steuernummer('289381508152')  # Prefix '28' is unique to BW
puts federal_12.state_name  # => "Baden-Württemberg"

# ❌ Requires explicit state for ambiguous prefixes
begin
  Steuer.steuernummer('304881508155')  # Prefix '3' shared by BB, SN, ST
rescue Steuer::UnsupportedStateError => e
  puts e.message  # => "Cannot determine state from tax number..."
end

# ✅ Works with explicit state for ambiguous cases
ambiguous = Steuer.steuernummer('304881508155', state: 'BB')
puts ambiguous.state_code  # => "BB"

Ambiguous vs Unambiguous Prefixes

✅ Unambiguous prefixes (auto-detected):

  • 28 → Baden-Württemberg
  • 9 → Bayern
  • 11 → Berlin
  • 24 → Bremen
  • 22 → Hamburg
  • 26 → Hessen
  • 23 → Niedersachsen
  • 5 → Nordrhein-Westfalen
  • 27 → Rheinland-Pfalz
  • 1 → Saarland
  • 21 → Schleswig-Holstein

❌ Ambiguous prefixes (require explicit state):

  • 3 → Brandenburg, Sachsen, or Sachsen-Anhalt
  • 4 → Mecklenburg-Vorpommern or Thüringen

Error Handling

begin
  # Invalid format
  Steuer.steuernummer('invalid')
rescue Steuer::InvalidTaxNumberError => e
  puts "Invalid format: #{e.message}"
end

begin
  # Unsupported state or undetectable
  Steuer.steuernummer('99/999/99999')
rescue Steuer::UnsupportedStateError => e
  puts "Unsupported state: #{e.message}"
end

Supported German States

The gem supports all 16 German states (Bundesländer):

State CodeState NameStandard Format Example12-digit Example13-digit Example
BWBaden-Württemberg93/815/081522893815081522893081508152
BYBayern181/815/081559181815081559181081508155
BEBerlin21/815/081501121815081501121081508150
BBBrandenburg048/815/081553048815081553048081508155
HBBremen75/815/081522475815081522475081508152
HHHamburg02/815/081562202815081562202081508156
HEHessen013/815/081532613815081532613081508153
MVMecklenburg-Vorpommern79/815/081514079815081514079081508151
NINiedersachsen24/815/081512324815081512324081508151
NWNordrhein-Westfalen133/8150/81595133815081595133081508159
RPRheinland-Pfalz22/815/081542722815081542722081508154
SLSaarland010/815/081821010815081821010081508182
SNSachsen201/815/081563201815081563201081508156
STSachsen-Anhalt101/815/081533101815081533101081508153
SHSchleswig-Holstein01/815/081552101815081552101081508155
THThüringen151/815/081544151815081544151081508154

API Reference

Steuer.steuernummer(tax_number, state_code = nil)

Creates a new Steuer::Steuernummer object.

Parameters:

  • tax_number (String): The tax number in any supported format
  • state_code (String, optional): The German state code (auto-detected if not provided)

Returns: Steuer::Steuernummer instance

Steuer::Steuernummer Methods

Instance Methods

  • valid? - Returns true if the tax number is valid
  • to_federal_12 - Converts to 12-digit unified federal scheme
  • to_federal_13 - Converts to 13-digit electronic transmission format
  • to_standard - Converts to standard state-specific format
  • state_code - Returns the German state code (e.g., "BW")
  • state_name - Returns the full state name (e.g., "Baden-Württemberg")
  • format_type - Returns the detected format (:standard, :federal_12, or :federal_13)
  • original_input - Returns the original input string

Development

After checking out the repo, run:

bundle install

To run the tests:

bundle exec rspec

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

Future Features

This gem is designed to be extensible. Planned features include:

  • German VAT number validation
  • Steuer-ID (tax identification number) handling
  • Wirtschafts-Identifikationsnummer support
  • Additional German tax system utilities

References

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 23 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts