Class: VatInfo::Models::VatPayer

Inherits:
Object
  • Object
show all
Defined in:
lib/vat_info/models/vat_payer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ VatPayer

Returns a new instance of VatPayer.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/vat_info/models/vat_payer.rb', line 6

def initialize(params)
  @data                       = {}
  @data[:nespolehlivy_platce] = params.fetch(:@nespolehlivy_platce)
  @data[:dic]                 = params.fetch(:@dic)
  @data[:datum_zverejneni]    = params[:@datum_zverejneni_nespolehlivosti]
  @data[:cislo_fu]            = params[:@cislo_fu]
  accounts                    = params[:zverejnene_ucty]
  @data[:ucty]                = accounts ? create_accounts(accounts[:ucet]) : {}
rescue KeyError => e
  raise InvalidStructure, "Response XML is missing required attributes.\n" \
                          "Input params were: #{params}\n" \
                          "Rescued error: #{e}"
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



4
5
6
# File 'lib/vat_info/models/vat_payer.rb', line 4

def data
  @data
end

Instance Method Details

#create_accounts(accounts) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/vat_info/models/vat_payer.rb', line 20

def create_accounts(accounts)
  VatInfo::Utils.wrap_in_array(accounts).map do ||
    standard     = [:standardni_ucet]
    non_standard = [:nestandardni_ucet]

    params = standard ? (standard) : (non_standard)
    params.merge(datum_zverejneni: [:@datum_zverejneni])
  end
end

#non_standard_account(data) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/vat_info/models/vat_payer.rb', line 39

def (data)
  {
    predcisli:  nil,
    cislo:      nil,
    kod_banky:  nil,
    iban:       data[:@cislo]
  }
end

#standard_account(data) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/vat_info/models/vat_payer.rb', line 30

def (data)
  {
    predcisli:  data[:@predcisli],
    cislo:      data[:@cislo],
    kod_banky:  data[:@kod_banky],
    iban:       nil
  }
end