rixml 0.0.3 → 0.0.4

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 (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +70 -0
  3. data/lib/rixml.rb +18 -9
  4. data/rixml.gemspec +2 -2
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 663a393ffceccb1ca7c2fc2612b5a9d1f83f4a0a
4
- data.tar.gz: 42ae751148768797f65e52ffacdcb868127217ed
3
+ metadata.gz: d6a3aa2d504041ca967ac507d4e3adef0e6d7b11
4
+ data.tar.gz: c85bce14f429ae939edc3a1b1376f85afb7a4d70
5
5
  SHA512:
6
- metadata.gz: f92d85f912c86b0bd1c556efb5b08b3e7675b205c723b6b53bf48e8bf34004dbd5b2e248d9139db059b298864d6723869fd379f64e69168a1f392b10685859c9
7
- data.tar.gz: 28767532e1e034600cdbc7c46e4344f5d37190b6445032708fda8c323ee0b5f36a0d302d8e777383103b1316f7b101590c7e96923ad206864cd029b3ad9bad80
6
+ metadata.gz: f1c74e082bbfd329c53149e06081876e191e4b0eebbd02ec773f9482e9cb41862b4358f1839b396b2d060ac4a0984a8598069669e306a7fd73303289a57081a3
7
+ data.tar.gz: 047685a3e4dad4cac25debdd6c92b4a6bd8f65007a63e01fabaa644e5ab7f75ee9c5c29a0573c481f85b33b25f68d5aa696893f9239d42bc7d05615dc475ec81
data/README.md CHANGED
@@ -0,0 +1,70 @@
1
+ # RIXML - simple DSL for parse rixml.
2
+
3
+ [![Build Status](https://travis-ci.org/AlphaExchange/rixml.svg?branch=master)](https://travis-ci.org/AlphaExchange/rixml)
4
+
5
+ A simple RIXML parser for Ruby.
6
+
7
+ * Main page: https://github.com/AlphaExchange/rixml
8
+
9
+ ## Usage
10
+
11
+ Basic usage:
12
+
13
+ ```ruby
14
+ require 'rixml'
15
+
16
+ #parse from file
17
+ rixml = RIXML.parse_from_file('./test/fixtures/simple.xml')
18
+
19
+ #parse from string
20
+ rixml = RIXML.parse('<xml></xml>')
21
+
22
+ #parse from File
23
+ rixml = RIXML.new(File)
24
+ ```
25
+
26
+ Now you should be able to get info about RIXML.
27
+
28
+ ```ruby
29
+ # rixml.product_id
30
+ 095ad669-9f01-421e-91a0-c6c9e78a3c9d
31
+
32
+ # rixml.status
33
+ revised
34
+
35
+ # rixml.publication_date
36
+ instance of Time
37
+
38
+ # rixml.authors
39
+
40
+ {
41
+ name: 'Leonardo Siqueira',
42
+ first_name: 'Leonardo',
43
+ middle_name: 'Goularte',
44
+ last_name: 'Siqueira',
45
+ job_title: 'Awesome Job',
46
+ email: 'leonardo@alpha-exchange.com'
47
+ }
48
+
49
+
50
+ # rixml.report_info
51
+
52
+ {
53
+ title: 'Title',
54
+ abstract: 'We initiate coverage with a Buy rating. We believe the stock is deeply undervalued...',
55
+ file_name: 'sample.pdf',
56
+ pages: 2
57
+ }
58
+
59
+ # rixml.context
60
+ {
61
+ companies: companies: [{ isin: 'GOOG11234' }],
62
+ sectors: [{ code: 45101010, focus: true }]
63
+ }
64
+
65
+ ```
66
+
67
+
68
+ ## Legal
69
+
70
+ Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
data/lib/rixml.rb CHANGED
@@ -9,23 +9,24 @@ class RIXML
9
9
  end
10
10
 
11
11
  def product_id
12
- @attrs['Research']['Product']['productID']
12
+ deep_value('Research', 'Product', 'productID')
13
13
  end
14
14
 
15
15
  def status
16
- @attrs['Research']['Product']['StatusInfo']['statusType'].try(:downcase).try(:to_sym) || :published
16
+ deep_value('Research', 'Product', 'StatusInfo', 'statusType').try(:downcase).try(:to_sym) || :published
17
17
  end
18
18
 
19
19
  def publication_date
20
- DateTime.strptime(@attrs['Research']['Product']['StatusInfo']['statusDateTime'])
20
+ time_str = deep_value('Research', 'Product', 'StatusInfo', 'statusDateTime') || DateTime.now.to_s
21
+ DateTime.strptime(time_str)
21
22
  end
22
23
 
23
24
  def authors
24
- org = @attrs['Research']['Product']['Source']['Organization']
25
+ org = deep_value('Research', 'Product', 'Source', 'Organization') || {}
25
26
  if org.is_a? Array
26
27
  org = org.find { |v| v['primaryIndicator'] == 'Yes' } || org.first
27
28
  end
28
- authors = org['PersonGroup']['PersonGroupMember']
29
+ authors = RIXML.deep_value(org, 'PersonGroup', 'PersonGroupMember') || []
29
30
  authors = [authors] unless authors.is_a? Array
30
31
 
31
32
  authors.map do |author|
@@ -42,17 +43,17 @@ class RIXML
42
43
  end
43
44
 
44
45
  def report_info
45
- content = @attrs['Research']['Product']['Content']
46
+ content = deep_value('Research', 'Product', 'Content')
46
47
  {
47
48
  title: content['Title'],
48
49
  abstract: content['Abstract'],
49
- file_name: content['Resource']['Name'],
50
- pages: content['Resource']['Length'].to_i
50
+ file_name: content['Resource'].try(:[], 'Name'),
51
+ pages: content['Resource'].try(:[], 'Length').to_i
51
52
  }
52
53
  end
53
54
 
54
55
  def context
55
- context = @attrs['Research']['Product']['Context']
56
+ context = deep_value('Research', 'Product', 'Context')
56
57
  context_info = {
57
58
  companies: RIXML.extract_companies_from_context(context),
58
59
  sectors: RIXML.extract_sectors_from_context(context)
@@ -69,6 +70,14 @@ class RIXML
69
70
 
70
71
  private
71
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
+
72
81
  def self.read_file filename
73
82
  body = ''
74
83
  File.open(filename, 'r') do |infile|
data/rixml.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rixml'
3
- s.version = '0.0.3'
4
- s.date = '2016-06-09'
3
+ s.version = '0.0.4'
4
+ s.date = '2016-11-01'
5
5
  s.summary = "RIXML Parser"
6
6
  s.description = "Parse RIXML files"
7
7
  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.3
4
+ version: 0.0.4
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-06-09 00:00:00.000000000 Z
12
+ date: 2016-11-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler