Sha256: bcc9256b24ed90cabba46501a39318c6e6c60115d0110205f2ba7be4d109211b

Contents?: true

Size: 842 Bytes

Versions: 2

Compression:

Stored size: 842 Bytes

Contents

class Valvat
  def initialize(raw)
    @raw = raw || ""
    @vat_country_code, @to_s_wo_country = to_a
  end
  
  attr_reader :raw, :vat_country_code, :to_s_wo_country
  
  def valid?
    Valvat::Syntax.validate(self)
  end
  
  def exists?
    Valvat::Lookup.validate(self)
  end
  
  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/lookup'
require 'valvat/version'
require 'valvat/active_model' if defined?(ActiveModel)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
valvat-0.2.1 lib/valvat.rb
valvat-0.2.0 lib/valvat.rb