Sha256: 24a30c7a40de57ac9613df579e59c29f77b3a8a9f6e11a17c0015e8ee05815c2

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

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

module ItaxCode
  class << self
    ##
    # This method encodes citizen tax code
    #
    # @example
    #
    #   ItaxCode.generate({
    #     surname:    [String]
    #     name:       [String]
    #     gender:     [String]
    #     birthdate:  [Date, DateTime, Time]
    #     birthplace: [String]
    #   })
    #
    # @param [Hash] data The citizen data attributes
    #
    # @return [String]

    def encode(data)
      Encoder.new(data).encode
    end

    ##
    # This method decodes tax code in its components
    #
    # @example
    #
    #   ItaxCode.decode("CCCFBA85D03L219P")
    #
    # @param [String] tax_code The citizen tax code
    #
    # @return [Hash]

    def decode(tax_code)
      Parser.new(tax_code).decode
    end

    ##
    # This method check given tax code validity
    # against new one generated by citizen informations
    #
    # @example
    #
    #  ItaxCode.valid?(tax_code [String], {
    #     surname:    [String]
    #     name:       [String]
    #     gender:     [String]
    #     birthdate:  [Date, DateTime, Time]
    #     birthplace: [String]
    #  })
    #
    # @return [true, false]

    def valid?(tax_code, data)
      Validator.new(data).valid?(tax_code)
    end
  end

  class Error < StandardError; end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
itax_code-0.1.2 lib/itax_code.rb