Sha256: 0b6d84817f826b43c42016dd1350c4348cea38c775af2bbed4eef2511970a9e9

Contents?: true

Size: 968 Bytes

Versions: 6

Compression:

Stored size: 968 Bytes

Contents

# frozen_string_literal: true

class Valvat
  def initialize(raw)
    @raw = Valvat::Utils.normalize(raw || '')
    @vat_country_code, @to_s_wo_country = to_a
  end

  attr_reader :raw, :vat_country_code, :to_s_wo_country

  def blank?
    raw.nil? || raw.strip == ''
  end

  def valid?
    Valvat::Syntax.validate(self)
  end

  def valid_checksum?
    Valvat::Checksum.validate(self)
  end

  def iso_country_code
    Valvat::Utils.vat_country_to_iso_country(vat_country_code)
  end

  # TODO: Remove method / not in use
  def european?
    Valvat::Utils::EU_MEMBER_STATES.include?(iso_country_code)
  end

  def to_a
    Valvat::Utils.split(raw)
  end

  def to_s
    raw
  end

  def inspect
    "#<Valvat #{[raw, iso_country_code].compact.join(' ')}>"
  end
end

def Valvat(vat) # rubocop:disable Naming/MethodName
  vat.is_a?(Valvat) ? vat : Valvat.new(vat)
end

require 'valvat/utils'
require 'valvat/syntax'
require 'valvat/checksum'
require 'valvat/version'

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
valvat-1.1.5 lib/valvat/local.rb
valvat-1.1.4 lib/valvat/local.rb
valvat-1.1.3 lib/valvat/local.rb
valvat-1.1.2 lib/valvat/local.rb
valvat-1.1.1 lib/valvat/local.rb
valvat-1.1.0 lib/valvat/local.rb