lib/rixml.rb in rixml-0.1.1 vs lib/rixml.rb in rixml-0.1.2
- old
+ new
@@ -53,11 +53,11 @@
pages: content['Resource']&.dig('Length').to_i
}
end
def context
- context = @attrs.dig('Research', 'Product', 'Context')
+ context = @attrs.dig('Research', 'Product', 'Context') || {}
{
companies: parse_companies_from_context(context),
sectors: parse_sectors_from_context(context),
countries: parse_countries_from_context(context)
}
@@ -85,33 +85,30 @@
{ code: v['code'].to_i, focus: v['focusLevel'].try(:downcase) == 'yes' }
end
end
def parse_countries_from_context(context)
- [context['ProductClassifications']&.dig('Country')].flatten.map do |country|
+ [context['ProductClassifications']&.dig('Country')].flatten.compact.map do |country|
{ code: country['code'].upcase }
end
end
def parse_companies_from_context(context)
companies = []
[context['IssuerDetails']].flatten.compact.each do |issuer|
- list = issuer.try(:[], 'Issuer')
- next if list.nil?
- list = [list] unless list.is_a? Array
- list.select { |c| c['issuerType'] == 'Corporate' }.each do |company|
- companies << parse_company_info(company)
+ [issuer['Issuer']].flatten.compact.select { |c| c['issuerType'] == 'Corporate' }.each do |company|
+ companies << parse_company_info(company).merge(primary: company['primaryIndicator'] == 'Yes')
end
end
companies
end
def parse_company_info(company)
security_ids = company.dig('SecurityDetails', 'Security', 'SecurityID')
- security_ids = [security_ids] unless security_ids.is_a? Array
- ids = security_ids.map do |security_id|
+ security_ids = [security_ids].compact unless security_ids.is_a? Array
+ ids = security_ids&.map do |security_id|
{ security_id['idType'].underscore.to_sym => security_id['idValue'] }
- end.reduce({}, :merge)
- info = { name: (company.dig('IssuerName') || [])['NameValue'] }
+ end&.reduce({}, :merge) || []
+ info = { name: (company.dig('IssuerName') || {})['NameValue'] }
info.merge(ids)
end
end