lib/rixml.rb in rixml-0.4.6 vs lib/rixml.rb in rixml-0.4.7

- old
+ new

@@ -82,11 +82,12 @@ context = @attrs.dig('Research', 'Product', 'Context') || {} { 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) + category: parse_product_category_from_context(context), + publication_date: parse_publication_date_from_context(context) } end def xpath(path) @document.xpath(path) @@ -111,14 +112,30 @@ 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 + email: person['ContactInfo']&.dig('Email')&.downcase, # TODO: Remove: Use email from contacts + contacts: parse_author_contacts(person['ContactInfo']) } end + def parse_author_contacts(contacts) + contacts = [contacts] unless contacts.is_a? Array + + contacts.map do |contact| + { + email: contact&.dig('Email')&.downcase, + phone: parse_author_contact_phone(contact&.dig('Phone')) + } + end + end + + def parse_author_contact_phone(phone) + [phone['CountryCode'], phone['Number']].join(' ') if phone + end + def parse_sectors_from_context(context) list = context['ProductClassifications'].try(:[], 'SectorIndustry') return [] if list.nil? list = [list] unless list.is_a? Array list.select { |s| s['classificationType'] == 'GICS' }.map do |v| @@ -142,9 +159,13 @@ companies.flatten end def parse_product_category_from_context(context) context.dig('ProductDetails', 'ProductCategory', 'productCategory') + end + + def parse_publication_date_from_context(context) + context.dig('ProductDetails', 'publicationDateTime') end def parse_company_info(company) securities = company.dig('SecurityDetails', 'Security') securities = [securities].compact unless securities.is_a? Array