lib/rixml.rb in rixml-0.4.8 vs lib/rixml.rb in rixml-0.4.9
- old
+ new
@@ -104,23 +104,30 @@
def resource_length(resource)
length = resource&.dig('Length')
return length.to_i if length.respond_to?(:to_i)
end
+ # rubocop:disable Metrics/MethodLength
def parse_info_from_author(author)
person = author&.dig('Person')
{
+ primary: primary?(author.dig('primaryIndicator')),
name: person['DisplayName'],
first_name: person['GivenName'],
middle_name: person['MiddleName'],
last_name: person['FamilyName'],
job_title: person['JobTitle'],
email: person['ContactInfo']&.dig('Email')&.downcase, # TODO: Remove: Use email from contacts
contacts: parse_author_contacts(person['ContactInfo'])
}
end
+ # rubocop:enable Metrics/MethodLength
+ def primary?(primary_indicator)
+ primary_indicator == 'Yes'
+ end
+
def parse_author_contacts(contacts)
contacts = [contacts] unless contacts.is_a? Array
contacts.map do |contact|
{
@@ -172,17 +179,29 @@
def parse_company_info(company)
securities = company.dig('SecurityDetails', 'Security')
securities = [securities].compact unless securities.is_a? Array
securities.map do |security|
info = { name: (company.dig('IssuerName') || {})['NameValue'], primary: company['primaryIndicator'] == 'Yes' }
- info.merge(parse_security_info(security))
+ info = info.merge(parse_security_info(security))
+ info.merge(securities: parse_securities(security)) # Keep retrocompatibility adding a new key 'securities'
end
end
def parse_security_info(security)
security_ids = security.dig('SecurityID')
security_ids = [security_ids].compact unless security_ids.is_a? Array
security_ids&.map do |security_id|
{ security_id['idType'].underscore.to_sym => security_id['idValue'] }
end&.reduce({}, :merge) || []
+ end
+
+ def parse_securities(security)
+ security_ids = security.dig('SecurityID')
+ security_ids = [security_ids].compact unless security_ids.is_a? Array
+ security_ids&.map do |security_id|
+ {
+ primary: primary?(security.dig('primaryIndicator')),
+ security_id['idType'].underscore.to_sym => security_id['idValue']
+ }
+ end
end
end