lib/rixml.rb in rixml-0.2.2 vs lib/rixml.rb in rixml-0.3.0
- old
+ new
@@ -117,21 +117,28 @@
def parse_companies_from_context(context)
companies = []
[context['IssuerDetails']].flatten.compact.each do |issuer|
[issuer['Issuer']].flatten.compact.select { |c| c['issuerType'] == 'Corporate' }.each do |company|
- companies << parse_company_info(company).merge(primary: company['primaryIndicator'] == 'Yes')
+ companies << parse_company_info(company)
end
end
- companies
+ companies.flatten
end
def parse_company_info(company)
- security_ids = company.dig('SecurityDetails', 'Security', 'SecurityID')
+ 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))
+ end
+ end
+
+ def parse_security_info(security)
+ security_ids = security.dig('SecurityID')
security_ids = [security_ids].compact unless security_ids.is_a? Array
- ids = security_ids&.map do |security_id|
+ security_ids&.map do |security_id|
{ security_id['idType'].underscore.to_sym => security_id['idValue'] }
end&.reduce({}, :merge) || []
- info = { name: (company.dig('IssuerName') || {})['NameValue'] }
- info.merge(ids)
end
end