Class: VatCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/vat_check.rb,
lib/vat_check/format.rb,
lib/vat_check/utility.rb,
lib/vat_check/version.rb,
lib/vat_check/requests.rb

Defined Under Namespace

Modules: Format, Request, Utility

Constant Summary collapse

VERSION =
'1.0.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vat) ⇒ VatCheck

Returns a new instance of VatCheck.



9
10
11
12
13
14
15
# File 'lib/vat_check.rb', line 9

def initialize(vat)
  @vat = vat
  @regex = VatCheck::Format.valid?(@vat)
  @response = @regex ? VatCheck::Request.lookup(@vat) : {}
  @vies_available = @response.has_key?(:valid)
  @vies = @vies_available ? @response[:valid] : false
end

Instance Attribute Details

#regexObject (readonly)

Returns the value of attribute regex.



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

def regex
  @regex
end

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

#viesObject (readonly)

Returns the value of attribute vies.



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

def vies
  @vies
end

#vies_availableObject (readonly)

Returns the value of attribute vies_available.



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

def vies_available
  @vies_available
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/vat_check.rb', line 23

def exists?
  return @vies
end

#valid?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/vat_check.rb', line 17

def valid?
  return false unless @regex
  return @regex unless @vies_available
  return @vies
end