Hash: select entries by keys

This commit is contained in:
Karl Erik Õunapuu 2021-01-07 13:59:12 +02:00
parent c23075fa19
commit c58b4fb2e9
No known key found for this signature in database
GPG key ID: C9DD647298A34764
11 changed files with 201 additions and 141 deletions

View file

@ -1,8 +1,7 @@
module Deserializers
module Xml
class Domain
attr_reader :frame
attr_reader :registrar
attr_reader :frame, :registrar
def initialize(frame, registrar)
@frame = frame
@ -15,15 +14,24 @@ module Deserializers
registrar_id: registrar,
registrant_id: if_present('registrant'),
reserved_pw: if_present('reserved > pw'),
period: frame.css('period').text.present? ? Integer(frame.css('period').text) : 1,
period_unit: frame.css('period').first ? frame.css('period').first[:unit] : 'y',
}
attributes.merge!(assign_period_attributes)
pw = frame.css('authInfo > pw').text
attributes[:transfer_code] = pw if pw.present?
attributes.compact
end
def assign_period_attributes
period = frame.css('period')
{
period: period.text.present? ? Integer(period.text) : 1,
period_unit: period.first ? period.first[:unit] : 'y',
}
end
def if_present(css_path)
return if frame.css(css_path).blank?