Sha256: e37cd54d32b9a6d86c6376eed8faed389332e2748f8163dcd2a70d9dbe35a65d

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

require "active_support/all"

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

module ItaxCode
  class << self
    # Encodes 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 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 against new one
    # encoded from user informations.
    #
    # @param [String] tax_code 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 [Boolean]
    def valid?(tax_code, data)
      Validator.new(data).valid?(tax_code)
    end
  end

  class Error < StandardError; end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
itax_code-0.3.0 lib/itax_code.rb
itax_code-0.2.0 lib/itax_code.rb
itax_code-0.1.4 lib/itax_code.rb