Sha256: db816e174ae3c91a643232bccf8c070bdae9ea45a217fb54f9543ddd8c0b8934

Contents?: true

Size: 830 Bytes

Versions: 3

Compression:

Stored size: 830 Bytes

Contents

module ItaxCode
  class Omocode
    attr_reader :tax_code, :utils

    # Creates a new instance for a given tax_code.
    #
    # @param [String] tax_code
    # @param [Utils]  utils
    def initialize(tax_code, utils = Utils.new)
      @tax_code = tax_code
      @utils    = utils
    end

    # Computes the omocodes from a given tax_code.
    #
    # @return [Array]
    def list
      chars = tax_code[0..14].chars
      (omocodes(:decode, chars) + omocodes(:encode, chars)).uniq
    end

    private

      def omocodes(action, chars)
        utils.omocodia_subs_indexes.reverse.map do |i|
          chars[i] = utils.public_send("omocodia_#{action}".to_sym, chars[i])
          omocode(chars)
        end
      end

      def omocode(chars)
        code = chars.join
        code + utils.encode_cin(code)
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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