rixml 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rixml.rb +12 -20
  3. data/rixml.gemspec +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6a3aa2d504041ca967ac507d4e3adef0e6d7b11
4
- data.tar.gz: c85bce14f429ae939edc3a1b1376f85afb7a4d70
3
+ metadata.gz: 20cca52a1d30a894e95eeceed322f062f382bf6a
4
+ data.tar.gz: 0bf86162ce9a93da4d7cb8ad51b4f360f9071c91
5
5
  SHA512:
6
- metadata.gz: f1c74e082bbfd329c53149e06081876e191e4b0eebbd02ec773f9482e9cb41862b4358f1839b396b2d060ac4a0984a8598069669e306a7fd73303289a57081a3
7
- data.tar.gz: 047685a3e4dad4cac25debdd6c92b4a6bd8f65007a63e01fabaa644e5ab7f75ee9c5c29a0573c481f85b33b25f68d5aa696893f9239d42bc7d05615dc475ec81
6
+ metadata.gz: 4e005de2177272d0893508810b39077c03c2c6ca2d8e162f50283157624e3d9be29d0c44413ebf15f6647574f4f9dc5b840788c7c199b95eaf3ed74de64d5baa
7
+ data.tar.gz: 4992aa24a2a0eb0eccb824e6693f5406dc8f7068973eec828542ec60089635a93786e13a1b81849df1421c6f399f8dacb0c080958986152f43ac4637cf8c2974
data/lib/rixml.rb CHANGED
@@ -9,24 +9,24 @@ class RIXML
9
9
  end
10
10
 
11
11
  def product_id
12
- deep_value('Research', 'Product', 'productID')
12
+ @attrs.dig('Research', 'Product', 'productID')
13
13
  end
14
14
 
15
15
  def status
16
- deep_value('Research', 'Product', 'StatusInfo', 'statusType').try(:downcase).try(:to_sym) || :published
16
+ @attrs.dig('Research', 'Product', 'StatusInfo', 'statusType')&.downcase&.to_sym || :published
17
17
  end
18
18
 
19
19
  def publication_date
20
- time_str = deep_value('Research', 'Product', 'StatusInfo', 'statusDateTime') || DateTime.now.to_s
20
+ time_str = @attrs.dig('Research', 'Product', 'StatusInfo', 'statusDateTime') || DateTime.now.to_s
21
21
  DateTime.strptime(time_str)
22
22
  end
23
23
 
24
24
  def authors
25
- org = deep_value('Research', 'Product', 'Source', 'Organization') || {}
25
+ org = @attrs.dig('Research', 'Product', 'Source', 'Organization') || {}
26
26
  if org.is_a? Array
27
27
  org = org.find { |v| v['primaryIndicator'] == 'Yes' } || org.first
28
28
  end
29
- authors = RIXML.deep_value(org, 'PersonGroup', 'PersonGroupMember') || []
29
+ authors = org.dig('PersonGroup', 'PersonGroupMember') || []
30
30
  authors = [authors] unless authors.is_a? Array
31
31
 
32
32
  authors.map do |author|
@@ -37,23 +37,23 @@ class RIXML
37
37
  middle_name: person['MiddleName'],
38
38
  last_name: person['FamilyName'],
39
39
  job_title: person['JobTitle'],
40
- email: person['ContactInfo'].try(:[], 'Email').try(:downcase)
40
+ email: person['ContactInfo']&.dig('Email')&.downcase
41
41
  }
42
42
  end
43
43
  end
44
44
 
45
45
  def report_info
46
- content = deep_value('Research', 'Product', 'Content')
46
+ content = @attrs.dig('Research', 'Product', 'Content')
47
47
  {
48
48
  title: content['Title'],
49
49
  abstract: content['Abstract'],
50
- file_name: content['Resource'].try(:[], 'Name'),
51
- pages: content['Resource'].try(:[], 'Length').to_i
50
+ file_name: content['Resource']&.dig('Name'),
51
+ pages: content['Resource']&.dig('Length').to_i
52
52
  }
53
53
  end
54
54
 
55
55
  def context
56
- context = deep_value('Research', 'Product', 'Context')
56
+ context = @attrs.dig('Research', 'Product', 'Context')
57
57
  context_info = {
58
58
  companies: RIXML.extract_companies_from_context(context),
59
59
  sectors: RIXML.extract_sectors_from_context(context)
@@ -70,14 +70,6 @@ class RIXML
70
70
 
71
71
  private
72
72
 
73
- def self.deep_value(attrs, *keys)
74
- keys.reduce(attrs) { |v, key| v.try(:[], key) }
75
- end
76
-
77
- def deep_value(*keys)
78
- RIXML.deep_value(@attrs, *keys)
79
- end
80
-
81
73
  def self.read_file filename
82
74
  body = ''
83
75
  File.open(filename, 'r') do |infile|
@@ -94,10 +86,10 @@ class RIXML
94
86
  return [] if list.nil?
95
87
  list = [list] unless list.is_a? Array
96
88
  list.select { |c| c['issuerType'] == 'Corporate' }.each do |company|
97
- securities = company['SecurityDetails']['Security']['SecurityID']
89
+ securities = company.dig('SecurityDetails', 'Security', 'SecurityID')
98
90
  securities = [securities] unless securities.is_a? Array
99
91
  isin = securities.find { |security| security['idType'] == 'ISIN' }
100
- companies << { isin: isin['idValue'] } unless isin.nil?
92
+ companies << { isin: isin['idValue'] } unless isin&.dig('idValue').nil?
101
93
  end
102
94
  companies
103
95
  end
data/rixml.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rixml'
3
- s.version = '0.0.4'
3
+ s.version = '0.0.5'
4
4
  s.date = '2016-11-01'
5
5
  s.summary = "RIXML Parser"
6
6
  s.description = "Parse RIXML files"
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
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Correia Santos