rixml 0.4.9 → 0.5.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: 25f629105503be64d6300105901129fcb5255c85
4
- data.tar.gz: 53141679e00fee5e8f7aa363e1d67958e4dddb8e
3
+ metadata.gz: ef1a6d79daadb500b55c10fcb4e88efa1449ddd2
4
+ data.tar.gz: 13963adef0e74d8e131f3ea7ceb2d73134f8ff07
5
5
  SHA512:
6
- metadata.gz: d7e3ba7ae9511506b9fe3085faed86d7aadf6fc906c6bfc134595b38d88e63db5fdd1edf6680e19df48836aaeacd7bba764e1c68bc8e4b82a400fd9c9e43397c
7
- data.tar.gz: 68da09018210d6f6b27613c8b15c3d9191603e6ae64700face8366f0868e0a61f9a08315086a05f70b444262d1de73a6f9f0cdcb455d2a2501eafd8962d81bff
6
+ metadata.gz: 79fc5901cb630c28b1e557d4d79a32dbf4511e460e71f48d70ae5688c767b2c91c9df5c43b4892312e2fb37dd6522c5b8b05e1ec72a042e09ce04112555ebfb8
7
+ data.tar.gz: 967df4ef556a4795cca31207ce1d0431b2ff1c6ad7dae788711c9e24f0d6013429e6661dd050c943bdc6a9a12c28c81862b2e042b0d2ee51884d38472280e15b
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -11,5 +11,6 @@ AllCops:
11
11
  DisplayCopNames: true
12
12
  DisplayStyleGuide: true
13
13
  Exclude:
14
+ - 'spec/**/*'
14
15
  - 'test/**/*'
15
16
  - 'vendor/**/*'
@@ -4,11 +4,12 @@ PATH
4
4
  rixml (0.0.0)
5
5
  activesupport (>= 4.0.0)
6
6
  nokogiri (~> 1.5)
7
+ nokogiri-happymapper (~> 0.6.0)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
- activesupport (5.1.2)
12
+ activesupport (5.1.4)
12
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
14
  i18n (~> 0.7)
14
15
  minitest (~> 5.1)
@@ -16,17 +17,33 @@ GEM
16
17
  ast (2.3.0)
17
18
  byebug (9.0.6)
18
19
  concurrent-ruby (1.0.5)
20
+ diff-lcs (1.3)
19
21
  i18n (0.8.6)
20
- mini_portile2 (2.2.0)
22
+ mini_portile2 (2.3.0)
21
23
  minitest (5.10.1)
22
- nokogiri (1.8.0)
23
- mini_portile2 (~> 2.2.0)
24
+ nokogiri (1.8.1)
25
+ mini_portile2 (~> 2.3.0)
26
+ nokogiri-happymapper (0.6.0)
27
+ nokogiri (~> 1.5)
24
28
  parser (2.4.0.0)
25
29
  ast (~> 2.2)
26
30
  powerpack (0.1.1)
27
31
  rainbow (2.2.2)
28
32
  rake
29
33
  rake (11.3.0)
34
+ rspec (3.6.0)
35
+ rspec-core (~> 3.6.0)
36
+ rspec-expectations (~> 3.6.0)
37
+ rspec-mocks (~> 3.6.0)
38
+ rspec-core (3.6.0)
39
+ rspec-support (~> 3.6.0)
40
+ rspec-expectations (3.6.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.6.0)
43
+ rspec-mocks (3.6.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.6.0)
46
+ rspec-support (3.6.0)
30
47
  rubocop (0.45.0)
31
48
  parser (>= 2.3.1.1, < 3.0)
32
49
  powerpack (~> 0.1)
@@ -48,6 +65,7 @@ DEPENDENCIES
48
65
  minitest (~> 5.1)
49
66
  rake (~> 11.3)
50
67
  rixml!
68
+ rspec (~> 3.6)
51
69
  rubocop (~> 0.45.0)
52
70
 
53
71
  BUNDLED WITH
data/circle.yml CHANGED
@@ -4,5 +4,6 @@ machine:
4
4
  test:
5
5
  override:
6
6
  - bundle exec rake
7
+ - bundle exec rspec
7
8
  post:
8
9
  - bundle exec rubocop
@@ -3,6 +3,7 @@ require 'nokogiri'
3
3
  require 'date'
4
4
  require 'active_support/core_ext/hash/conversions'
5
5
  require 'active_support/inflector/inflections'
6
+ require_relative './rixml_document'
6
7
 
7
8
  # rubocop:disable Metrics/ClassLength
8
9
  class RIXML
@@ -13,11 +14,16 @@ class RIXML
13
14
  end
14
15
 
15
16
  def initialize(data)
17
+ @data = data
16
18
  @document = Nokogiri::XML(data)
17
19
  @attrs = Hash.from_xml(@document.root.to_s)
18
20
  @document.remove_namespaces!
19
21
  end
20
22
 
23
+ def research
24
+ @rixml_document ||= RixmlDocument.parse(@data)
25
+ end
26
+
21
27
  def product_id
22
28
  @attrs.dig('Research', 'Product', 'productID')
23
29
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ require_relative './rixml_document/research'
3
+
4
+ module RixmlDocument
5
+ def self.parse(xml)
6
+ RixmlDocument::Research.parse(xml)
7
+ end
8
+
9
+ def self.parse_from_file(filename)
10
+ xml = File.read(filename)
11
+ parse(xml)
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ require 'happymapper'
3
+ require_relative './node'
4
+ require_relative './rixml_type/normalized_string'
5
+
6
+ module RixmlDocument
7
+ class AssetClass < Node
8
+ include HappyMapper
9
+ tag 'AssetClass'
10
+
11
+ attribute :asset_class, RixmlType::NormalizedString, tag: 'assetClass'
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ require 'happymapper'
3
+ require_relative './node'
4
+ require_relative './issuer'
5
+ require_relative './rixml_type/yes_no_boolean'
6
+
7
+ module RixmlDocument
8
+ class IssuerDetails < Node
9
+ include HappyMapper
10
+ tag 'IssuerDetails'
11
+ has_many :issuers, Issuer, tag: 'Issuer', xpath: './'
12
+ end
13
+
14
+ class Context < Node
15
+ include HappyMapper
16
+ tag 'Context'
17
+
18
+ has_one :issuer_details, IssuerDetails, xpath: './'
19
+
20
+ attribute :external, RixmlType::YesNoBoolean
21
+
22
+ def issuers
23
+ issuer_details.issuers
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ require 'happymapper'
3
+ require_relative './node'
4
+ require_relative './security'
5
+ require_relative './rixml_type/normalized_string'
6
+ require_relative './rixml_type/upcase_string'
7
+ require_relative './rixml_type/yes_no_boolean'
8
+
9
+ module RixmlDocument
10
+ class SecurityDetails < Node
11
+ include HappyMapper
12
+ has_many :securities, Security, tag: 'Security', xpath: './'
13
+ end
14
+
15
+ class Issuer < Node
16
+ include HappyMapper
17
+ tag 'Issuer'
18
+
19
+ has_one :security_details, SecurityDetails, tag: 'SecurityDetails', xpath: './'
20
+
21
+ attribute :primary_indicator, RixmlType::YesNoBoolean, tag: 'primaryIndicator'
22
+ attribute :issuer_type, RixmlType::NormalizedString, tag: 'issuerType'
23
+ attribute :domicile_country_code, RixmlType::UpcaseString, tag: 'domicileCountryCode'
24
+
25
+ def securities
26
+ security_details.securities
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ module RixmlDocument
3
+ class Node
4
+ def to_hash
5
+ hash = {}
6
+ attributes = self.class.instance_variable_get(:@attributes)
7
+ elements = self.class.instance_variable_get(:@elements)
8
+ (attributes.to_a + elements.to_a).each do |k, _|
9
+ value = send(k)
10
+ hash[k] = serialize_attribute(value)
11
+ end
12
+ hash
13
+ end
14
+
15
+ private
16
+
17
+ def serialize_attribute(attribute)
18
+ if attribute.is_a?(Array)
19
+ attribute.map { |a| serialize_attribute(a) }
20
+ elsif attribute.respond_to?(:to_hash)
21
+ attribute.to_hash
22
+ else
23
+ attribute
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ require 'happymapper'
3
+ require_relative './node'
4
+ require_relative './context'
5
+ require_relative './rixml_type/yes_no_boolean'
6
+
7
+ module RixmlDocument
8
+ class Product < Node
9
+ include HappyMapper
10
+ tag 'Product'
11
+
12
+ has_one :context, Context, tag: 'Context', xpath: './'
13
+
14
+ attribute :product_id, String, tag: 'productID'
15
+ attribute :event_indicator, RixmlType::YesNoBoolean, tag: 'eventIndicator'
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require 'happymapper'
3
+ require_relative './node'
4
+ require_relative './product'
5
+ require_relative './rixml_type/normalized_string'
6
+
7
+ module RixmlDocument
8
+ class Research < Node
9
+ include HappyMapper
10
+ tag 'Research'
11
+
12
+ has_one :product, Product, tag: 'Product', xpath: './'
13
+
14
+ attribute :research_id, String, tag: 'researchID'
15
+ attribute :created_date_time, Time, tag: 'createDateTime'
16
+ attribute :language, RixmlType::NormalizedString
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ require 'happymapper'
3
+ require 'active_support/core_ext/string'
4
+
5
+ module RixmlDocument
6
+ module RixmlType
7
+ class NormalizedString
8
+ def self.parse(value)
9
+ value.to_s.underscore.downcase
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ HappyMapper::SupportedTypes.register_type(RixmlDocument::RixmlType::NormalizedString) do |value|
16
+ RixmlDocument::RixmlType::NormalizedString.parse(value)
17
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ require 'happymapper'
3
+
4
+ module RixmlDocument
5
+ module RixmlType
6
+ class UpcaseString
7
+ def self.parse(value)
8
+ value.to_s.upcase
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ HappyMapper::SupportedTypes.register_type(RixmlDocument::RixmlType::UpcaseString) do |value|
15
+ RixmlDocument::RixmlType::UpcaseString.parse(value)
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ require 'happymapper'
3
+
4
+ module RixmlDocument
5
+ module RixmlType
6
+ class YesNoBoolean
7
+ def self.parse(value)
8
+ value.to_s.casecmp('yes').zero?
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ HappyMapper::SupportedTypes.register_type(RixmlDocument::RixmlType::YesNoBoolean) do |value|
15
+ RixmlDocument::RixmlType::YesNoBoolean.parse(value)
16
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require 'happymapper'
3
+ require_relative './node'
4
+ require_relative './security_id'
5
+ require_relative './asset_class'
6
+ require_relative './security_type'
7
+ require_relative './rixml_type/yes_no_boolean'
8
+
9
+ module RixmlDocument
10
+ class Security < Node
11
+ include HappyMapper
12
+ tag 'Security'
13
+
14
+ has_many :security_ids, SecurityId, tag: 'SecurityID', xpath: './'
15
+ has_one :asset_class, AssetClass, tag: 'AssetClass', xpath: './'
16
+ has_one :security_type, SecurityType, tag: 'SecurityType', xpath: './'
17
+
18
+ element :security_name, String, tag: 'SecurityName'
19
+
20
+ attribute :primary_indicator, RixmlType::YesNoBoolean, tag: 'primaryIndicator'
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ require 'happymapper'
3
+ require_relative './node'
4
+ require_relative './rixml_type/normalized_string'
5
+ require_relative './rixml_type/upcase_string'
6
+
7
+ module RixmlDocument
8
+ class SecurityId < Node
9
+ include HappyMapper
10
+ tag 'SecurityID'
11
+
12
+ attribute :id_type, RixmlType::NormalizedString, tag: 'idType'
13
+ attribute :id_value, String, tag: 'idValue'
14
+ attribute :trading_country_code, RixmlType::UpcaseString, tag: 'tradingCountryCode'
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ require 'happymapper'
3
+ require_relative './node'
4
+ require_relative './rixml_type/normalized_string'
5
+
6
+ module RixmlDocument
7
+ class SecurityType < Node
8
+ include HappyMapper
9
+ tag 'SecurityType'
10
+
11
+ attribute :security_type, RixmlType::NormalizedString, tag: 'securityType'
12
+ end
13
+ end
@@ -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.4.9'
5
- s.date = '2017-09-29'
4
+ s.version = '0.5.0'
5
+ s.date = '2017-10-06'
6
6
  s.summary = 'RIXML Parser'
7
7
  s.description = 'Parse RIXML files'
8
8
  s.homepage = 'https://github.com/AlphaExchange/rixml'
@@ -16,10 +16,12 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_development_dependency 'bundler', '~> 1.12'
18
18
  s.add_development_dependency 'minitest', '~> 5.1'
19
+ s.add_development_dependency 'rspec', '~> 3.6'
19
20
  s.add_development_dependency 'rake', '~> 11.3'
20
21
  s.add_development_dependency 'rubocop', '~> 0.45.0'
21
22
  s.add_development_dependency 'byebug'
22
23
 
23
24
  s.add_runtime_dependency 'nokogiri', '~> 1.5'
24
25
  s.add_runtime_dependency 'activesupport', '>= 4.0.0'
26
+ s.add_runtime_dependency 'nokogiri-happymapper', '~> 0.6.0'
25
27
  end
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.4.9
4
+ version: 0.5.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: 2017-09-29 00:00:00.000000000 Z
12
+ date: 2017-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '5.1'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.6'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.6'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: rake
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -109,6 +123,20 @@ dependencies:
109
123
  - - ">="
110
124
  - !ruby/object:Gem::Version
111
125
  version: 4.0.0
126
+ - !ruby/object:Gem::Dependency
127
+ name: nokogiri-happymapper
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: 0.6.0
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: 0.6.0
112
140
  description: Parse RIXML files
113
141
  email:
114
142
  - alex@alpha-exchange.com
@@ -118,6 +146,7 @@ extensions: []
118
146
  extra_rdoc_files: []
119
147
  files:
120
148
  - ".gitignore"
149
+ - ".rspec"
121
150
  - ".rubocop.yml"
122
151
  - Gemfile
123
152
  - Gemfile.lock
@@ -125,6 +154,19 @@ files:
125
154
  - Rakefile
126
155
  - circle.yml
127
156
  - lib/rixml.rb
157
+ - lib/rixml_document.rb
158
+ - lib/rixml_document/asset_class.rb
159
+ - lib/rixml_document/context.rb
160
+ - lib/rixml_document/issuer.rb
161
+ - lib/rixml_document/node.rb
162
+ - lib/rixml_document/product.rb
163
+ - lib/rixml_document/research.rb
164
+ - lib/rixml_document/rixml_type/normalized_string.rb
165
+ - lib/rixml_document/rixml_type/upcase_string.rb
166
+ - lib/rixml_document/rixml_type/yes_no_boolean.rb
167
+ - lib/rixml_document/security.rb
168
+ - lib/rixml_document/security_id.rb
169
+ - lib/rixml_document/security_type.rb
128
170
  - release
129
171
  - rixml.gemspec
130
172
  homepage: https://github.com/AlphaExchange/rixml