Sha256: 07986aa050c53f65439ec63d6bac572395d24fc9e101676d2105d4ff9d60bafb

Contents?: true

Size: 1.12 KB

Versions: 11

Compression:

Stored size: 1.12 KB

Contents

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 exists?(options={})
    Valvat::Lookup.validate(self, options)
  end
  alias_method :exist?, :exists?

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

  def european?
    Valvat::Utils::EU_COUNTRIES.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)
  vat.is_a?(Valvat) ? vat : Valvat.new(vat)
end

require 'valvat/utils'
require 'valvat/syntax'
require 'valvat/checksum'
require 'valvat/lookup'
require 'valvat/lookup/request'
require 'valvat/lookup/request_with_id'
require 'valvat/version'
require 'active_model/validations/valvat_validator' if defined?(ActiveModel)

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
valvat-0.7.0 lib/valvat.rb
valvat-0.6.11 lib/valvat.rb
valvat-0.6.10 lib/valvat.rb
valvat-0.6.9 lib/valvat.rb
valvat-0.6.8 lib/valvat.rb
valvat-0.6.7 lib/valvat.rb
valvat-0.6.6 lib/valvat.rb
valvat-0.6.5 lib/valvat.rb
valvat-0.6.4 lib/valvat.rb
valvat-0.6.3 lib/valvat.rb
valvat-0.6.2 lib/valvat.rb