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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f45aee55fc7aa52f1466fb86ac7d59c86b086fe
4
- data.tar.gz: d8124698b7c21bfeb7cc7125ad92abe1405a617c
3
+ metadata.gz: fe64331340a5f8adcf7138880b3ae7dd9feed396
4
+ data.tar.gz: b01ad830ad052f03396a39dcb51a90eea80fe404
5
5
  SHA512:
6
- metadata.gz: 24f4059210991529d1908aac481de94b73af48a9485943001fbf6913b77e662446910c660543d661d05f11b0d94886cee05211b8162c61399a36ae2291ffd5c5
7
- data.tar.gz: 16558436d7c255c44acd5d0bf4880d1d5e4223a7cfa7689acd0fb83f4d3bc9ddbf0784a5c84d7ee42e55000877ec1ba496687af46ab06e2be7be3f674f79be90
6
+ metadata.gz: 8c60f9ca93affbdec5e498a1352e3d7106d03c27186946acc40314f81bbc51ede6a182cd365943248fdfda596d6e73abef8886e66c7de180920687ef182eecb2
7
+ data.tar.gz: 194bd2506825cd49253ba9388c3175d7bd973e8a81b07f7950bc431ca7185919ce9fce1e35dfbd02043cb4585d598dbc27b51d81e15d6bef1c02431852cdab06
data/.rubocop.yml CHANGED
@@ -1,5 +1,7 @@
1
1
  Style/Documentation:
2
2
  Enabled: false
3
+ Metrics/ClassLength:
4
+ Max: 120
3
5
  Metrics/LineLength:
4
6
  Max: 120
5
7
  AllCops:
@@ -8,4 +10,4 @@ AllCops:
8
10
  DisplayStyleGuide: true
9
11
  Exclude:
10
12
  - 'test/**/*'
11
- - 'vendor/**/*'
13
+ - 'vendor/**/*'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rixml (0.0.6)
4
+ rixml (0.1.0)
5
5
  activesupport (>= 4.0.0)
6
6
  nokogiri (~> 1.5)
7
7
 
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 do |author|
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
- { companies: RIXML.extract_companies_from_context(context), sectors: RIXML.extract_sectors_from_context(context) }
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
- def self.parse(data)
66
- RIXML.new(Nokogiri::XML(data).root)
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 self.parse_from_file(filename)
70
- parse read_file(filename)
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 self.read_file(filename)
74
- body = ''.dup
75
- File.open(filename, 'r') do |infile|
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
- # rubocop:disable Metrics/AbcSize
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
- securities = company.dig('SecurityDetails', 'Security', 'SecurityID')
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 self.extract_sectors_from_context(context)
102
- list = context['ProductClassifications'].try(:[], 'SectorIndustry')
103
- return [] if list.nil?
104
- list = [list] unless list.is_a? Array
105
- list.select { |s| s['classificationType'] == 'GICS' }.map do |v|
106
- { code: v['code'].to_i, focus: v['focusLevel'].try(:downcase) == 'yes' }
107
- end
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.6'
5
- s.date = '2016-11-01'
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.6
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-11-01 00:00:00.000000000 Z
12
+ date: 2016-12-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler