bvbg 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 798141952881d32dfb3e23eda35e22a710aaefbe
4
+ data.tar.gz: b402fde85459e3fe10cb517d2e93de8e4e2ba489
5
+ SHA512:
6
+ metadata.gz: fc978103923c1008a56a501e7e0f6dc2f767f30ae20bffe1e2094feb607a662e71c3874c9eeefc599965663a7d7410b1a9ace7cd74c56da18fae1764aba1a377
7
+ data.tar.gz: 790ef4d52fb1f2443adc51f913e5637dcb0ca1491b5d71c7c443f4788d3df49b70e697636fb040dbce0936568c2b9ce3e1b03cbfc085a9a8c9eb6d3480262849
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.2
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in bvbg.gemspec
6
+ gemspec
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bvbg (0.1.0)
5
+ ox
6
+ saxerator
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.2)
12
+ diff-lcs (1.3)
13
+ ffi (1.9.25)
14
+ formatador (0.2.5)
15
+ guard (2.14.2)
16
+ formatador (>= 0.2.4)
17
+ listen (>= 2.7, < 4.0)
18
+ lumberjack (>= 1.0.12, < 2.0)
19
+ nenv (~> 0.1)
20
+ notiffany (~> 0.0)
21
+ pry (>= 0.9.12)
22
+ shellany (~> 0.0)
23
+ thor (>= 0.18.1)
24
+ guard-compat (1.2.1)
25
+ guard-rspec (4.7.3)
26
+ guard (~> 2.1)
27
+ guard-compat (~> 1.1)
28
+ rspec (>= 2.99.0, < 4.0)
29
+ listen (3.0.8)
30
+ rb-fsevent (~> 0.9, >= 0.9.4)
31
+ rb-inotify (~> 0.9, >= 0.9.7)
32
+ lumberjack (1.0.13)
33
+ method_source (0.9.0)
34
+ nenv (0.3.0)
35
+ notiffany (0.1.1)
36
+ nenv (~> 0.1)
37
+ shellany (~> 0.0)
38
+ ox (2.10.0)
39
+ pry (0.11.3)
40
+ coderay (~> 1.1.0)
41
+ method_source (~> 0.9.0)
42
+ rake (10.5.0)
43
+ rb-fsevent (0.10.3)
44
+ rb-inotify (0.9.10)
45
+ ffi (>= 0.5.0, < 2)
46
+ rspec (3.8.0)
47
+ rspec-core (~> 3.8.0)
48
+ rspec-expectations (~> 3.8.0)
49
+ rspec-mocks (~> 3.8.0)
50
+ rspec-core (3.8.0)
51
+ rspec-support (~> 3.8.0)
52
+ rspec-expectations (3.8.2)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.8.0)
55
+ rspec-mocks (3.8.0)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.8.0)
58
+ rspec-support (3.8.0)
59
+ saxerator (0.9.8)
60
+ shellany (0.0.1)
61
+ terminal-notifier (2.0.0)
62
+ thor (0.20.0)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ bundler (~> 1.16)
69
+ bvbg!
70
+ guard-rspec
71
+ rake (~> 10.0)
72
+ rspec (~> 3.0)
73
+ terminal-notifier
74
+
75
+ BUNDLED WITH
76
+ 1.16.1
@@ -0,0 +1,78 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec feature)
6
+ directories %w(lib spec)
7
+
8
+ ## Uncomment to clear the screen before every task
9
+ # clearing :on
10
+
11
+ ## Guard internally checks for changes in the Guardfile and exits.
12
+ ## If you want Guard to automatically start up again, run guard in a
13
+ ## shell loop, e.g.:
14
+ ##
15
+ ## $ while bundle exec guard; do echo "Restarting Guard..."; done
16
+ ##
17
+ ## Note: if you are using the `directories` clause above and you are not
18
+ ## watching the project directory ('.'), the you will want to move the Guardfile
19
+ ## to a watched dir and symlink it back, e.g.
20
+ #
21
+ # $ mkdir config
22
+ # $ mv Guardfile config/
23
+ # $ ln -s config/Guardfile .
24
+ #
25
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
26
+
27
+ # Note: The cmd option is now required due to the increasing number of ways
28
+ # rspec may be run, below are examples of the most common uses.
29
+ # * bundler: 'bundle exec rspec'
30
+ # * bundler binstubs: 'bin/rspec'
31
+ # * spring: 'bin/rspec' (This will use spring if running and you have
32
+ # installed the spring binstubs per the docs)
33
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
34
+ # * 'just' rspec: 'rspec'
35
+
36
+ guard :rspec, cmd: "bundle exec rspec" do
37
+ require "guard/rspec/dsl"
38
+ dsl = Guard::RSpec::Dsl.new(self)
39
+
40
+ # Feel free to open issues for suggestions and improvements
41
+
42
+ # RSpec files
43
+ rspec = dsl.rspec
44
+ watch(rspec.spec_helper) { rspec.spec_dir }
45
+ watch(rspec.spec_support) { rspec.spec_dir }
46
+ watch(rspec.spec_files)
47
+
48
+ # Ruby files
49
+ ruby = dsl.ruby
50
+ dsl.watch_spec_files_for(ruby.lib_files)
51
+
52
+ # Rails files
53
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
54
+ dsl.watch_spec_files_for(rails.app_files)
55
+ dsl.watch_spec_files_for(rails.views)
56
+
57
+ watch(rails.controllers) do |m|
58
+ [
59
+ rspec.spec.("routing/#{m[1]}_routing"),
60
+ rspec.spec.("controllers/#{m[1]}_controller"),
61
+ rspec.spec.("acceptance/#{m[1]}")
62
+ ]
63
+ end
64
+
65
+ # Rails config changes
66
+ watch(rails.spec_helper) { rspec.spec_dir }
67
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
68
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
69
+
70
+ # Capybara features specs
71
+ watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
72
+
73
+ # Turnip features and steps
74
+ watch(%r{^spec/acceptance/(.+)\.feature$})
75
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
76
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
77
+ end
78
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Pedro Aguiar dos Santos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # Bvbg
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bvbg`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'bvbg'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install bvbg
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bvbg.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bvbg"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "bvbg/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bvbg"
8
+ spec.version = Bvbg::VERSION
9
+ spec.authors = ["Pedro Aguiar dos Santos"]
10
+ spec.email = ["pedro.santos@investtools.com.br"]
11
+
12
+ spec.summary = %q{Gem for reading Bovespa BVBG files}
13
+ spec.homepage = "https://github.com/investtools/bvbg.git"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against " \
22
+ # "public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.16"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "guard-rspec"
36
+ spec.add_development_dependency "terminal-notifier"
37
+ spec.add_dependency "saxerator"
38
+ spec.add_dependency "ox"
39
+ end
@@ -0,0 +1,5 @@
1
+ require "bvbg/version"
2
+ require 'saxerator'
3
+ require 'bvbg/bvbg86_handler'
4
+ require 'bvbg/bvbg87_handler'
5
+ require "bvbg/parser"
@@ -0,0 +1,47 @@
1
+ class Bvbg::Bvbg86Handler
2
+ def initialize(parser)
3
+ @parser = parser
4
+ end
5
+
6
+ def self.accept?(parser)
7
+ parser.for_tag(:BizGrpDtls).each do |file_type|
8
+ return true if file_type[:BizGrpTp].include?("86")
9
+ end
10
+ false
11
+ end
12
+
13
+ def all_lines
14
+ @parser.for_tag(:PricRpt).each do |item|
15
+ yield build_line(item)
16
+ end
17
+ end
18
+
19
+ def build_line(raw_item)
20
+ puts raw_item[:FinInstrmAttrbts][:BestBidPric]
21
+ {
22
+ name: raw_item[:SctyId][:TckrSymb],
23
+ symbol: raw_item[:SctyId][:TckrSymb],
24
+ close: raw_item[:FinInstrmAttrbts][:LastPric],
25
+ date: Date.parse(raw_item[:TradDt][:Dt]),
26
+ open: raw_item[:FinInstrmAttrbts][:FrstPric],
27
+ high: raw_item[:FinInstrmAttrbts][:MaxPric],
28
+ low: raw_item[:FinInstrmAttrbts][:MinPric],
29
+ average: raw_item[:FinInstrmAttrbts][:TradAvrgPric],
30
+ bid: raw_item[:FinInstrmAttrbts][:BestBidPric],
31
+ ask: raw_item[:FinInstrmAttrbts][:BestAskPric],
32
+ volume: raw_item[:FinInstrmAttrbts][:NtlFinVol],
33
+ quantity: raw_item[:FinInstrmAttrbts][:FinInstrmQty],
34
+ trades: raw_item[:TradDtls][:TradQty],
35
+ adj_close: raw_item[:FinInstrmAttrbts][:OscnPctg]
36
+ }
37
+ end
38
+
39
+ protected
40
+
41
+ def bd_or_nil(value)
42
+ if not value.nil?
43
+ return BigDecimal.new(value)
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,26 @@
1
+ class Bvbg::Bvbg87Handler
2
+ def initialize(parser)
3
+ @parser = parser
4
+ end
5
+
6
+ def self.accept?(parser)
7
+ parser.for_tag(:BizGrpDtls).each do |file_type|
8
+ return true if file_type[:BizGrpTp].include?("87")
9
+ end
10
+ false
11
+ end
12
+
13
+ def all_lines
14
+ @parser.for_tag(:IndxInf).each do |item|
15
+ yield build_line(item)
16
+ end
17
+ end
18
+
19
+ def build_line(raw_item)
20
+ {
21
+ symbol: raw_item[:SctyInf][:SctyId][:TckrSymb],
22
+ value: raw_item[:SctyInf][:ClsgPric]
23
+ }
24
+ end
25
+
26
+ end
@@ -0,0 +1,41 @@
1
+ class Bvbg::Parser
2
+
3
+ def initialize(file)
4
+ @file = file
5
+ @handlers = [Bvbg::Bvbg86Handler, Bvbg::Bvbg87Handler]
6
+ end
7
+
8
+ def parse
9
+ parser = Saxerator.parser(@file) do |config|
10
+ config.adapter = :ox
11
+ config.symbolize_keys!
12
+ end
13
+
14
+ handler = get_handler(parser)
15
+ raise "Unsupported file" unless not handler.nil?
16
+
17
+ lines = []
18
+
19
+ handler.all_lines do |line|
20
+ yield line if block_given?
21
+ lines << line
22
+ end
23
+
24
+ lines
25
+
26
+ end
27
+
28
+ def get_handler(parser)
29
+ supported_handler = nil
30
+
31
+ @handlers.each do |handler|
32
+ if handler.accept? parser
33
+ supported_handler = handler.new(parser)
34
+ end
35
+ end
36
+
37
+ supported_handler
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,3 @@
1
+ module Bvbg
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bvbg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Aguiar dos Santos
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: terminal-notifier
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: saxerator
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ox
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - pedro.santos@investtools.com.br
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - Guardfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - bvbg.gemspec
130
+ - lib/bvbg.rb
131
+ - lib/bvbg/bvbg86_handler.rb
132
+ - lib/bvbg/bvbg87_handler.rb
133
+ - lib/bvbg/parser.rb
134
+ - lib/bvbg/version.rb
135
+ homepage: https://github.com/investtools/bvbg.git
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.6.12
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Gem for reading Bovespa BVBG files
159
+ test_files: []