Class: Valvat

Inherits:
Object
  • Object
show all
Defined in:
lib/valvat.rb,
lib/valvat/error.rb,
lib/valvat/local.rb,
lib/valvat/utils.rb,
lib/valvat/lookup.rb,
lib/valvat/syntax.rb,
lib/valvat/version.rb,
lib/valvat/checksum.rb,
lib/valvat/checksum/at.rb,
lib/valvat/checksum/be.rb,
lib/valvat/checksum/bg.rb,
lib/valvat/checksum/cy.rb,
lib/valvat/checksum/de.rb,
lib/valvat/checksum/dk.rb,
lib/valvat/checksum/ee.rb,
lib/valvat/checksum/es.rb,
lib/valvat/checksum/fi.rb,
lib/valvat/checksum/fr.rb,
lib/valvat/checksum/gb.rb,
lib/valvat/checksum/gr.rb,
lib/valvat/checksum/hr.rb,
lib/valvat/checksum/hu.rb,
lib/valvat/checksum/ie.rb,
lib/valvat/checksum/it.rb,
lib/valvat/checksum/lt.rb,
lib/valvat/checksum/lu.rb,
lib/valvat/checksum/mt.rb,
lib/valvat/checksum/nl.rb,
lib/valvat/checksum/pl.rb,
lib/valvat/checksum/pt.rb,
lib/valvat/checksum/ro.rb,
lib/valvat/checksum/se.rb,
lib/valvat/checksum/si.rb,
lib/valvat/lookup/fault.rb,
lib/valvat/lookup/request.rb,
lib/valvat/lookup/response.rb

Defined Under Namespace

Modules: Checksum, Syntax, Utils Classes: Lookup, ViesError

Constant Summary collapse

Error =
Class.new(RuntimeError)
ViesMaintenanceError =
Class.new(ViesError)
ServiceUnavailable =
Class.new(ViesMaintenanceError)
MemberStateUnavailable =
Class.new(ViesMaintenanceError)
Timeout =
Class.new(ViesError)
InvalidRequester =
Class.new(ViesError)
BlockedError =
Class.new(ViesError)
RateLimitError =
Class.new(ViesError)
UnknownViesError =
Class.new(ViesError)
VERSION =
"0.9.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Valvat

Returns a new instance of Valvat.


2
3
4
5
# File 'lib/valvat/local.rb', line 2

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

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw


7
8
9
# File 'lib/valvat/local.rb', line 7

def raw
  @raw
end

#to_s_wo_countryObject (readonly)

Returns the value of attribute to_s_wo_country


7
8
9
# File 'lib/valvat/local.rb', line 7

def to_s_wo_country
  @to_s_wo_country
end

#vat_country_codeObject (readonly)

Returns the value of attribute vat_country_code


7
8
9
# File 'lib/valvat/local.rb', line 7

def vat_country_code
  @vat_country_code
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)

9
10
11
# File 'lib/valvat/local.rb', line 9

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

#european?Boolean

Returns:

  • (Boolean)

25
26
27
# File 'lib/valvat/local.rb', line 25

def european?
  Valvat::Utils::EU_COUNTRIES.include?(iso_country_code)
end

#exists?(options = {}) ⇒ Boolean Also known as: exist?

Returns:

  • (Boolean)

10
11
12
# File 'lib/valvat.rb', line 10

def exists?(options={})
  Valvat::Lookup.validate(self, options)
end

#inspectObject


37
38
39
# File 'lib/valvat/local.rb', line 37

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

#iso_country_codeObject


21
22
23
# File 'lib/valvat/local.rb', line 21

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

#to_aObject


29
30
31
# File 'lib/valvat/local.rb', line 29

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

#to_sObject


33
34
35
# File 'lib/valvat/local.rb', line 33

def to_s
  raw
end

#valid?Boolean

Returns:

  • (Boolean)

13
14
15
# File 'lib/valvat/local.rb', line 13

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

#valid_checksum?Boolean

Returns:

  • (Boolean)

17
18
19
# File 'lib/valvat/local.rb', line 17

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