class Valbn

Constants

EU_COUNTRIES
VERSION

Public Class Methods

abn=(value) click to toggle source
# File lib/valbn.rb, line 15
def self.abn=(value)
  @@abn = value # Valabn
  value ? require('valabn') : false
rescue
  raise StandardError, 'WARNING: Valnzbn not found. Please run `gem install valabn`.'
end
configure() { |self| ... } click to toggle source
# File lib/valbn.rb, line 29
def self.configure
  yield self
end
new(number, country) click to toggle source
# File lib/valbn.rb, line 33
def initialize(number, country)
  @country = country
  number = number.to_s.gsub(/\W/, '').upcase

  if EU_COUNTRIES.include?(country)
    vat_country = Valvat::Utils.iso_country_to_vat_country(country)
    number = "#{vat_country}#{number}" unless !!(number =~ /^#{vat_country}[A-Z0-9]+/) # add the country code if it does not exist
  end

  @number = number
end
nzbn=(value) click to toggle source
# File lib/valbn.rb, line 22
def self.nzbn=(value)
  @@abn = value # Valnzbn
  value ? require('valnzbn') : false
rescue
  raise StandardError, 'WARNING: Valnzbn not found. Please run `gem install valnzbn`.'
end
vatmoss=(value) click to toggle source
# File lib/valbn.rb, line 8
def self.vatmoss=(value)
  @@vatmoss = value # Valvat
  value ? require('valvat') : false
rescue
  raise StandardError, 'WARNING: Valvat not found. Please run `gem install valvat`.'
end

Public Instance Methods

exist?(options = {})
Alias for: exists?
exists?(options = {}) click to toggle source
# File lib/valbn.rb, line 45
def exists?(options = {})
  options[:detail] = options[:formatted]

  case @country
  when *EU_COUNTRIES
    if defined?(Valvat) == 'constant'
      result = Valvat.new(@number).exists?(options)

      if options[:formatted] == true && !result.nil? && result.is_a?(Hash)
        result = {
          original_format: result,
          name: result[:name],
          street_line_1: result[:address]
        }
      end
    else
      raise StandardError, 'WARNING: Valvat not found. Please run `gem install valvat`.'
    end
  when 'AU'
    if defined?(Valvat) == 'constant'
      result = Valabn.new(@number).exists?(options)

      if options[:formatted] == true && !result.nil? && result.is_a?(Hash)
        begin
          business = result[:search_by_ab_nv201408_response][:abr_payload_search_results][:response][:business_entity201408]
        rescue
          business = {}
        end

        result = {
          original_format: result,
          name: (business[:main_name] || {})[:organisation_name],
          region: (business[:main_business_physical_address] || {})[:state_code],
          postal_code: (business[:main_business_physical_address] || {})[:postcode]
        }
      end
    else
      raise StandardError, 'WARNING: Valnzbn not found. Please run `gem install valabn`.'
    end
  when 'NZ'
    if defined?(Valnzbn) == 'constant'
      result = Valnzbn.new(@number).exists?(options)
      if options[:formatted] == true && !result.nil? && result.is_a?(Hash)
        address = result[:registeredAddress] || [{}]

        result = {
          original_format: result,
          name: result[:entityName],
          street_line_1: address.first[:address1],
          street_line_2: address.first[:address2],
          city: address.first[:address3],
          postal_code: address.first[:postCode]
        }
      end
    else
      raise StandardError, 'WARNING: Valnzbn not found. Please run `gem install valnzbn`.'
    end
  end

  result
end
Also aliased as: exist?
iso_country_code() click to toggle source
# File lib/valbn.rb, line 108
def iso_country_code
  case @country
  when *EU_COUNTRIES
    Valvat.new(@number).iso_country_code
  else
    @country
  end
end