Sha256: accfe9ea0ed5d8db7479791451ce6b769cd6288d9895318b1693dfbd0c9a45b3

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require "itax_code/version"
require "itax_code/utils"
require "itax_code/encoder"
require "itax_code/parser"
require "itax_code/error"

module ItaxCode
  class << self
    # Encodes the user tax code.
    #
    # @param [Hash] data The user attributes
    #
    # @option data [String]       :surname
    # @option data [String]       :name
    # @option data [String]       :gender
    # @option data [String, Date] :birthdate
    # @option data [String]       :birthplace
    #
    # @return [String]
    def encode(data)
      Encoder.new(data).encode
    end

    # Decodes the tax code in its components.
    #
    # @param [String] tax_code The user tax code
    #
    # @return [Hash]
    def decode(tax_code)
      Parser.new(tax_code).decode
    end

    # Checks the given tax code validity.
    #
    # @param [String] tax_code The user tax code
    #
    # @return [Boolean]
    def valid?(tax_code)
      decode(tax_code)
      true
    rescue Parser::Error
      false
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
itax_code-2.0.5 lib/itax_code.rb
itax_code-2.0.3 lib/itax_code.rb
itax_code-2.0.2 lib/itax_code.rb