Class: VatInfo::Models::VatPayer
- Inherits:
-
Object
- Object
- VatInfo::Models::VatPayer
- Defined in:
- lib/vat_info/models/vat_payer.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #create_accounts(accounts) ⇒ Object
-
#initialize(params) ⇒ VatPayer
constructor
A new instance of VatPayer.
- #non_standard_account(data) ⇒ Object
- #standard_account(data) ⇒ Object
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
#data ⇒ Object
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 |account| standard = account[:standardni_ucet] non_standard = account[:nestandardni_ucet] params = standard ? standard_account(standard) : non_standard_account(non_standard) params.merge(datum_zverejneni: account[:@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 non_standard_account(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 standard_account(data) { predcisli: data[:@predcisli], cislo: data[:@cislo], kod_banky: data[:@kod_banky], iban: nil } end |