rixml 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -1
- data/Gemfile.lock +1 -1
- data/lib/rixml.rb +49 -43
- data/rixml.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe64331340a5f8adcf7138880b3ae7dd9feed396
|
4
|
+
data.tar.gz: b01ad830ad052f03396a39dcb51a90eea80fe404
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c60f9ca93affbdec5e498a1352e3d7106d03c27186946acc40314f81bbc51ede6a182cd365943248fdfda596d6e73abef8886e66c7de180920687ef182eecb2
|
7
|
+
data.tar.gz: 194bd2506825cd49253ba9388c3175d7bd973e8a81b07f7950bc431ca7185919ce9fce1e35dfbd02043cb4585d598dbc27b51d81e15d6bef1c02431852cdab06
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/lib/rixml.rb
CHANGED
@@ -2,8 +2,19 @@
|
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'date'
|
4
4
|
require 'active_support/core_ext/hash/conversions'
|
5
|
+
require 'active_support/inflector/inflections'
|
5
6
|
|
6
7
|
class RIXML
|
8
|
+
class << self
|
9
|
+
def parse(data)
|
10
|
+
RIXML.new(Nokogiri::XML(data).root)
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse_from_file(filename)
|
14
|
+
parse File.read(filename)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
7
18
|
def initialize(document)
|
8
19
|
@attrs = Hash.from_xml(document.to_s)
|
9
20
|
end
|
@@ -21,8 +32,6 @@ class RIXML
|
|
21
32
|
DateTime.strptime(time_str)
|
22
33
|
end
|
23
34
|
|
24
|
-
# rubocop:disable Metrics/AbcSize
|
25
|
-
# rubocop:disable Metrics/MethodLength
|
26
35
|
def authors
|
27
36
|
org = @attrs.dig('Research', 'Product', 'Source', 'Organization') || {}
|
28
37
|
if org.is_a? Array
|
@@ -31,20 +40,8 @@ class RIXML
|
|
31
40
|
authors = org.dig('PersonGroup', 'PersonGroupMember') || []
|
32
41
|
authors = [authors] unless authors.is_a? Array
|
33
42
|
|
34
|
-
authors.map
|
35
|
-
person = author['Person']
|
36
|
-
{
|
37
|
-
name: person['DisplayName'],
|
38
|
-
first_name: person['GivenName'],
|
39
|
-
middle_name: person['MiddleName'],
|
40
|
-
last_name: person['FamilyName'],
|
41
|
-
job_title: person['JobTitle'],
|
42
|
-
email: person['ContactInfo']&.dig('Email')&.downcase
|
43
|
-
}
|
44
|
-
end
|
43
|
+
authors.map { |author| parse_info_from_author(author) }
|
45
44
|
end
|
46
|
-
# rubocop:enable Metrics/AbcSize
|
47
|
-
# rubocop:enable Metrics/MethodLength
|
48
45
|
|
49
46
|
def report_info
|
50
47
|
content = @attrs.dig('Research', 'Product', 'Content')
|
@@ -59,51 +56,60 @@ class RIXML
|
|
59
56
|
|
60
57
|
def context
|
61
58
|
context = @attrs.dig('Research', 'Product', 'Context')
|
62
|
-
{
|
59
|
+
{
|
60
|
+
companies: parse_companies_from_context(context),
|
61
|
+
sectors: parse_sectors_from_context(context),
|
62
|
+
countries: parse_countries_from_context(context)
|
63
|
+
}
|
63
64
|
end
|
64
65
|
|
65
|
-
|
66
|
-
|
66
|
+
private
|
67
|
+
|
68
|
+
def parse_info_from_author(author)
|
69
|
+
person = author&.dig('Person')
|
70
|
+
{
|
71
|
+
name: person['DisplayName'],
|
72
|
+
first_name: person['GivenName'],
|
73
|
+
middle_name: person['MiddleName'],
|
74
|
+
last_name: person['FamilyName'],
|
75
|
+
job_title: person['JobTitle'],
|
76
|
+
email: person['ContactInfo']&.dig('Email')&.downcase
|
77
|
+
}
|
67
78
|
end
|
68
79
|
|
69
|
-
def
|
70
|
-
|
80
|
+
def parse_sectors_from_context(context)
|
81
|
+
list = context['ProductClassifications'].try(:[], 'SectorIndustry')
|
82
|
+
return [] if list.nil?
|
83
|
+
list = [list] unless list.is_a? Array
|
84
|
+
list.select { |s| s['classificationType'] == 'GICS' }.map do |v|
|
85
|
+
{ code: v['code'].to_i, focus: v['focusLevel'].try(:downcase) == 'yes' }
|
86
|
+
end
|
71
87
|
end
|
72
88
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
76
|
-
while (line = infile.gets)
|
77
|
-
body << line
|
78
|
-
end
|
89
|
+
def parse_countries_from_context(context)
|
90
|
+
[context['ProductClassifications']&.dig('Country')].flatten.map do |country|
|
91
|
+
{ code: country['code'].upcase }
|
79
92
|
end
|
80
|
-
body
|
81
93
|
end
|
82
94
|
|
83
|
-
|
84
|
-
# rubocop:disable Metrics/MethodLength
|
85
|
-
def self.extract_companies_from_context(context)
|
95
|
+
def parse_companies_from_context(context)
|
86
96
|
companies = []
|
87
97
|
list = context['IssuerDetails'].try(:[], 'Issuer')
|
88
98
|
return [] if list.nil?
|
89
99
|
list = [list] unless list.is_a? Array
|
90
100
|
list.select { |c| c['issuerType'] == 'Corporate' }.each do |company|
|
91
|
-
|
92
|
-
securities = [securities] unless securities.is_a? Array
|
93
|
-
isin = securities.find { |security| security['idType'] == 'ISIN' }
|
94
|
-
companies << { isin: isin['idValue'] } unless isin&.dig('idValue').nil?
|
101
|
+
companies << parse_company_info(company)
|
95
102
|
end
|
96
103
|
companies
|
97
104
|
end
|
98
|
-
# rubocop:enable Metrics/AbcSize
|
99
|
-
# rubocop:enable Metrics/MethodLength
|
100
105
|
|
101
|
-
def
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
106
|
+
def parse_company_info(company)
|
107
|
+
security_ids = company.dig('SecurityDetails', 'Security', 'SecurityID')
|
108
|
+
security_ids = [security_ids] unless security_ids.is_a? Array
|
109
|
+
ids = security_ids.map do |security_id|
|
110
|
+
{ security_id['idType'].underscore.to_sym => security_id['idValue'] }
|
111
|
+
end.reduce({}, :merge)
|
112
|
+
info = { name: (company.dig('IssuerName') || [])['NameValue'] }
|
113
|
+
info.merge(ids)
|
108
114
|
end
|
109
115
|
end
|
data/rixml.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = 'rixml'
|
4
|
-
s.version = '0.0
|
5
|
-
s.date = '2016-
|
4
|
+
s.version = '0.1.0'
|
5
|
+
s.date = '2016-12-01'
|
6
6
|
s.summary = 'RIXML Parser'
|
7
7
|
s.description = 'Parse RIXML files'
|
8
8
|
s.homepage = 'https://github.com/AlphaExchange/rixml'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rixml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Correia Santos
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-12-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|