lib/rixml.rb in rixml-0.6.0 vs lib/rixml.rb in rixml-0.6.1
- old
+ new
@@ -1,6 +1,7 @@
# frozen_string_literal: true
+
require 'nokogiri'
require 'date'
require 'active_support/core_ext/hash/conversions'
require 'active_support/inflector/inflections'
require_relative './rixml_document'
@@ -40,11 +41,11 @@
def status_info
time_str = current_status_info&.dig('statusDateTime') || DateTime.now.to_s
status = current_status_info&.dig('statusType')&.downcase&.to_sym || :published
{
status_type: status,
- status_date_time: Time.parse(time_str).to_datetime.to_s
+ status_date_time: Time.parse(time_str).to_datetime.to_s,
}
end
# @deprecated Please use {#status_info} instead
def publication_date
@@ -52,15 +53,15 @@
Time.parse(time_str).to_datetime.to_s
end
def authors
org = @attrs.dig('Research', 'Product', 'Source', 'Organization') || {}
- if org.is_a? Array
+ if org.is_a?(Array)
org = org.find { |v| v['primaryIndicator'] == 'Yes' } || org.first
end
authors = org.dig('PersonGroup', 'PersonGroupMember') || []
- authors = [authors] unless authors.is_a? Array
+ authors = [authors] unless authors.is_a?(Array)
authors.map { |author| parse_info_from_author(author) }
end
def report_info
@@ -69,11 +70,11 @@
title: content['Title'],
subtitle: content['SubTitle'],
abstract: content['Abstract'],
synopsis: content['Synopsis'],
file_name: content['Resource']&.dig('Name'),
- pages: resource_length(content['Resource'])
+ pages: resource_length(content['Resource']),
}
end
def asset_classes
assets = @attrs.dig('Research', 'Product', 'Source', 'Organization', 'Expertise', 'AssetClasses', 'AssetClass')
@@ -89,11 +90,11 @@
{
companies: parse_companies_from_context(context),
sectors: parse_sectors_from_context(context),
countries: parse_countries_from_context(context),
category: parse_product_category_from_context(context),
- publication_date: parse_publication_date_from_context(context)
+ publication_date: parse_publication_date_from_context(context),
}
end
def xpath(path)
@document.xpath(path)
@@ -101,11 +102,11 @@
private
def current_status_info
info = @attrs.dig('Research', 'Product', 'StatusInfo')
- info = [info] unless info.is_a? Array
+ info = [info] unless info.is_a?(Array)
info.find { |status| status&.dig('currentStatusIndicator')&.downcase == 'yes' } || info.first
end
def resource_length(resource)
length = resource&.dig('Length')
@@ -121,26 +122,26 @@
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'])
+ 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 = [contacts] unless contacts.is_a?(Array)
contacts.map do |contact|
{
email: contact&.dig('Email')&.downcase,
- phone: parse_author_contact_phone(contact&.dig('Phone'))
+ phone: parse_author_contact_phone(contact&.dig('Phone')),
}
end
end
def parse_author_contact_phone(phone)
@@ -148,11 +149,11 @@
end
def parse_sectors_from_context(context)
list = context['ProductClassifications'].try(:[], 'SectorIndustry')
return [] if list.nil?
- list = [list] unless list.is_a? Array
+ list = [list] unless list.is_a?(Array)
list.select { |s| s['classificationType'] == 'GICS' }.map do |v|
{ code: v['code'].to_i, focus: v['focusLevel'].try(:downcase) == 'yes' }
end
end
@@ -182,32 +183,32 @@
context.dig('ProductDetails', 'publicationDateTime')
end
def parse_company_info(company)
securities = company.dig('SecurityDetails', 'Security')
- securities = [securities].compact unless securities.is_a? Array
+ securities = [securities].compact unless securities.is_a?(Array)
securities.map do |security|
info = { name: (company.dig('IssuerName') || {})['NameValue'], primary: company['primaryIndicator'] == 'Yes' }
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 = [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 = [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']
+ security_id['idType'].underscore.to_sym => security_id['idValue'],
}
end
end
end