rixml 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/rixml.rb +105 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e295917f13d892bacc49df56551fb40b25146c78
|
4
|
+
data.tar.gz: 58e4567d1a03a020cfbd486b911f38cf7defae04
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8014d4a2f13843b9ab61c542eafd40a719d16f916808e7c0b6d38be6a2461bded32e5c1259c8cb0664680bc47634e7855cd0af5941d3127a67eaef87493fce6b
|
7
|
+
data.tar.gz: f299fcc9ce3476c4ff2af8032b26e892e01080870cf4a71e96cd65659871e79ad4b2ceae03b05178c6ddba8e3df9080c8bf33dd69a4382b57eec1c417c886242
|
data/lib/rixml.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'date'
|
3
|
+
require 'active_support/core_ext/hash/conversions'
|
4
|
+
|
5
|
+
class RIXML
|
6
|
+
|
7
|
+
def initialize(document)
|
8
|
+
@attrs = Hash.from_xml(document.to_s)
|
9
|
+
end
|
10
|
+
|
11
|
+
def product_id
|
12
|
+
@attrs['Research']['Product']['productID']
|
13
|
+
end
|
14
|
+
|
15
|
+
def status
|
16
|
+
@attrs['Research']['Product']['StatusInfo']['statusType'].try(:downcase).try(:to_sym) || :published
|
17
|
+
end
|
18
|
+
|
19
|
+
def publication_date
|
20
|
+
DateTime.strptime(@attrs['Research']['Product']['StatusInfo']['statusDateTime'])
|
21
|
+
end
|
22
|
+
|
23
|
+
def authors
|
24
|
+
org = @attrs['Research']['Product']['Source']['Organization']
|
25
|
+
if org.is_a? Array
|
26
|
+
org = org.find { |v| v['primaryIndicator'] == 'Yes' } || org.first
|
27
|
+
end
|
28
|
+
authors = org['PersonGroup']['PersonGroupMember']
|
29
|
+
authors = [authors] unless authors.is_a? Array
|
30
|
+
|
31
|
+
authors.map do |author|
|
32
|
+
person = author['Person']
|
33
|
+
{
|
34
|
+
name: person['DisplayName'],
|
35
|
+
first_name: person['GivenName'],
|
36
|
+
middle_name: person['MiddleName'],
|
37
|
+
last_name: person['FamilyName'],
|
38
|
+
job_title: person['JobTitle'],
|
39
|
+
email: person['ContactInfo'].try(:[], 'Email').try(:downcase)
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def report_info
|
45
|
+
content = @attrs['Research']['Product']['Content']
|
46
|
+
{
|
47
|
+
title: content['Title'],
|
48
|
+
abstract: content['Abstract'],
|
49
|
+
file_name: content['Resource']['Name'],
|
50
|
+
pages: content['Resource']['Length'].to_i
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def context
|
55
|
+
context = @attrs['Research']['Product']['Context']
|
56
|
+
context_info = {
|
57
|
+
companies: RIXML.extract_companies_from_context(context),
|
58
|
+
sectors: RIXML.extract_sectors_from_context(context)
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.parse data
|
63
|
+
RIXML.new(Nokogiri::XML(data).root)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.parse_from_file filename
|
67
|
+
self.parse self.read_file(filename)
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def self.read_file filename
|
73
|
+
body = ''
|
74
|
+
File.open(filename, 'r') do |infile|
|
75
|
+
while (line = infile.gets)
|
76
|
+
body << line
|
77
|
+
end
|
78
|
+
end
|
79
|
+
body
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.extract_companies_from_context context
|
83
|
+
companies = []
|
84
|
+
list = context['IssuerDetails'].try(:[], 'Issuer')
|
85
|
+
return [] if list.nil?
|
86
|
+
list = [list] unless list.is_a? Array
|
87
|
+
list.select { |c| c['issuerType'] == 'Corporate' }.each do |company|
|
88
|
+
securities = company['SecurityDetails']['Security']['SecurityID']
|
89
|
+
securities = [securities] unless securities.is_a? Array
|
90
|
+
isin = securities.find { |security| security['idType'] == 'ISIN' }
|
91
|
+
companies << { isin: isin['idValue'] } unless isin.nil?
|
92
|
+
end
|
93
|
+
companies
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.extract_sectors_from_context context
|
97
|
+
sectors = []
|
98
|
+
list = context['ProductClassifications'].try(:[], 'SectorIndustry')
|
99
|
+
return [] if list.nil?
|
100
|
+
list = [list] unless list.is_a? Array
|
101
|
+
list.select { |s| s['classificationType'] == 'GICS' }.map do |v|
|
102
|
+
{ code: v['code'].to_i, focus: v['focusLevel'].try(:downcase) == 'yes' }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rixml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Correia Santos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Parse RIXML files
|
14
|
+
email: alex@alpha-exchange.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/rixml.rb
|
20
|
+
homepage: ''
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.5.1
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: RIXML Parser
|
44
|
+
test_files: []
|