fundamentus_data 0.1.0 → 0.1.2
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.
- checksums.yaml +5 -5
- data/.gitignore +6 -5
- data/Gemfile +3 -3
- data/README.md +61 -61
- data/Rakefile +7 -7
- data/fundamentus_data.gemspec +15 -15
- data/lib/fundamentus_data/fundamentus_data.rb +20 -19
- data/lib/fundamentus_data/fundamentus_fetcher.rb +25 -25
- data/lib/fundamentus_data/fundamentus_parser.rb +64 -64
- data/lib/fundamentus_data/util/file_manager.rb +21 -21
- data/lib/fundamentus_data/util/url_fetcher.rb +29 -29
- data/lib/fundamentus_data.rb +1 -1
- data/test/config.rb +5 -5
- data/test/data/petr4.html +345 -345
- data/test/data/vale5.html +345 -345
- data/test/fundamentus_acceptance_test.rb +37 -42
- data/test/fundamentus_fetcher_test.rb +25 -27
- data/test/fundamentus_parser_test.rb +57 -57
- data/test/lib/local_file_fetcher.rb +17 -17
- data/test/output/.keep +0 -0
- metadata +3 -4
@@ -1,42 +1,37 @@
|
|
1
|
-
require_relative './config.rb'
|
2
|
-
|
3
|
-
class FundamentusAcceptanceTest < Minitest::Test
|
4
|
-
|
5
|
-
def test_save_financial_data
|
6
|
-
|
7
|
-
stocks = {
|
8
|
-
'PETR4' => { json_path: TEST_DIR + 'output/PETR4.json', json: petr4_json },
|
9
|
-
'VALE5' => { json_path: TEST_DIR + 'output/VALE5.json', json: vale5_json }
|
10
|
-
}
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
def vale5_json
|
39
|
-
'{"share_count":"5.365.300.000","market_cap":"158.169.000.000","last_processed":"31/12/2013","pl":"1.374,30","pvp":"1,07","pebit":"3,43","lpa":"0,02","vpa":"27,65","net_margin":"-0,3%","net_debt":"56.511.800.000","net_assets":"148.346.000.000","yearly_net_income":"101.490.000.000","yearly_net_profit":"115.091.000","quarterly_net_income":"28.626.200.000","quarterly_net_profit":"-14.867.100.000"}'
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
1
|
+
require_relative './config.rb'
|
2
|
+
|
3
|
+
class FundamentusAcceptanceTest < Minitest::Test
|
4
|
+
|
5
|
+
def test_save_financial_data
|
6
|
+
|
7
|
+
stocks = {
|
8
|
+
'PETR4' => { json_path: TEST_DIR + 'output/PETR4.json', json: petr4_json },
|
9
|
+
'VALE5' => { json_path: TEST_DIR + 'output/VALE5.json', json: vale5_json }
|
10
|
+
}
|
11
|
+
|
12
|
+
# Clean up previous tests output files
|
13
|
+
stocks.each do |code, info|
|
14
|
+
File.unlink(info[:json_path]) unless not File.exists?(info[:json_path])
|
15
|
+
end
|
16
|
+
|
17
|
+
fetcher = LocalFileFetcher.new(TEST_DIR + 'data/')
|
18
|
+
|
19
|
+
FundamentusData.save stocks.keys, TEST_DIR + 'output/', :fetcher => fetcher
|
20
|
+
|
21
|
+
stocks.each do |code, info|
|
22
|
+
assert_equal info[:json], File.open(info[:json_path]).read
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def petr4_json
|
30
|
+
'{"share_count":"13.044.500.000","market_cap":"201.407.000.000","last_processed":"31/12/2013","pl":"8,54","pvp":"0,58","pebit":"4,04","lpa":"1,81","vpa":"26,67","net_margin":"7,5%","net_debt":"221.549.000.000","net_assets":"347.940.000.000","yearly_net_income":"304.890.000.000","yearly_net_profit":"23.570.400.000","quarterly_net_income":"81.028.000.000","quarterly_net_profit":"6.281.530.000"}'
|
31
|
+
end
|
32
|
+
|
33
|
+
def vale5_json
|
34
|
+
'{"share_count":"5.365.300.000","market_cap":"158.169.000.000","last_processed":"31/12/2013","pl":"1.374,30","pvp":"1,07","pebit":"3,43","lpa":"0,02","vpa":"27,65","net_margin":"-0,3%","net_debt":"56.511.800.000","net_assets":"148.346.000.000","yearly_net_income":"101.490.000.000","yearly_net_profit":"115.091.000","quarterly_net_income":"28.626.200.000","quarterly_net_profit":"-14.867.100.000"}'
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -1,27 +1,25 @@
|
|
1
|
-
require_relative './config.rb'
|
2
|
-
|
3
|
-
class FundamentusFetcherTest < Minitest::Test
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@url_fetcher = MiniTest::Mock.new
|
7
|
-
@fundamentus_fetcher = FundamentusFetcher.new(@url_fetcher)
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_fetching_page_with_code_as_string
|
11
|
-
|
12
|
-
|
13
|
-
@
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
1
|
+
require_relative './config.rb'
|
2
|
+
|
3
|
+
class FundamentusFetcherTest < Minitest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@url_fetcher = MiniTest::Mock.new
|
7
|
+
@fundamentus_fetcher = FundamentusFetcher.new(@url_fetcher)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_fetching_page_with_code_as_string
|
11
|
+
expected_call_args = { 'VALE5' => 'https://www.fundamentus.com.br/detalhes.php?papel=VALE5' }
|
12
|
+
@url_fetcher.expect :fetch, nil, [expected_call_args]
|
13
|
+
@fundamentus_fetcher.fetch('VALE5')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_fetching_page_with_array_of_codes
|
17
|
+
expected_call_args = {
|
18
|
+
'VALE5' => 'https://www.fundamentus.com.br/detalhes.php?papel=VALE5',
|
19
|
+
'PETR4' => 'https://www.fundamentus.com.br/detalhes.php?papel=PETR4'
|
20
|
+
}
|
21
|
+
@url_fetcher.expect :fetch, nil, [expected_call_args]
|
22
|
+
@fundamentus_fetcher.fetch(['VALE5', 'PETR4'])
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -1,57 +1,57 @@
|
|
1
|
-
require_relative './config.rb'
|
2
|
-
|
3
|
-
class FundamentusParserTest < Minitest::Test
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@parser = FundamentusParser.new
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_parse_valid_file
|
10
|
-
|
11
|
-
assert_equal '5.365.300.000', @
|
12
|
-
assert_equal '158.169.000.000', @
|
13
|
-
assert_equal '31/12/2013', @
|
14
|
-
assert_equal '1.374,30', @
|
15
|
-
assert_equal '1,07', @
|
16
|
-
assert_equal '3,43', @
|
17
|
-
assert_equal '0,02', @
|
18
|
-
assert_equal '27,65', @
|
19
|
-
assert_equal '-0,3%', @
|
20
|
-
assert_equal '56.511.800.000', @
|
21
|
-
assert_equal '148.346.000.000', @
|
22
|
-
assert_equal '101.490.000.000', @
|
23
|
-
assert_equal '115.091.000', @
|
24
|
-
assert_equal '28.626.200.000', @
|
25
|
-
assert_equal '-14.867.100.000', @
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_parse_invalid_file
|
29
|
-
|
30
|
-
assert_nil @
|
31
|
-
assert_nil @
|
32
|
-
assert_nil @
|
33
|
-
assert_nil @
|
34
|
-
assert_nil @
|
35
|
-
assert_nil @
|
36
|
-
assert_nil @
|
37
|
-
assert_nil @
|
38
|
-
assert_nil @
|
39
|
-
assert_nil @
|
40
|
-
assert_nil @
|
41
|
-
assert_nil @
|
42
|
-
assert_nil @
|
43
|
-
assert_nil @
|
44
|
-
assert_nil @
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
1
|
+
require_relative './config.rb'
|
2
|
+
|
3
|
+
class FundamentusParserTest < Minitest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@parser = FundamentusParser.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_parse_valid_file
|
10
|
+
@data = @parser.parse(valid_content)
|
11
|
+
assert_equal '5.365.300.000', @data[:share_count]
|
12
|
+
assert_equal '158.169.000.000', @data[:market_cap]
|
13
|
+
assert_equal '31/12/2013', @data[:last_processed]
|
14
|
+
assert_equal '1.374,30', @data[:pl]
|
15
|
+
assert_equal '1,07', @data[:pvp]
|
16
|
+
assert_equal '3,43', @data[:pebit]
|
17
|
+
assert_equal '0,02', @data[:lpa]
|
18
|
+
assert_equal '27,65', @data[:vpa]
|
19
|
+
assert_equal '-0,3%', @data[:net_margin]
|
20
|
+
assert_equal '56.511.800.000', @data[:net_debt]
|
21
|
+
assert_equal '148.346.000.000', @data[:net_assets]
|
22
|
+
assert_equal '101.490.000.000', @data[:yearly_net_income]
|
23
|
+
assert_equal '115.091.000', @data[:yearly_net_profit]
|
24
|
+
assert_equal '28.626.200.000', @data[:quarterly_net_income]
|
25
|
+
assert_equal '-14.867.100.000', @data[:quarterly_net_profit]
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_parse_invalid_file
|
29
|
+
@data = @parser.parse(invalid_content)
|
30
|
+
assert_nil @data[:share_count]
|
31
|
+
assert_nil @data[:market_cap]
|
32
|
+
assert_nil @data[:last_processed]
|
33
|
+
assert_nil @data[:pl]
|
34
|
+
assert_nil @data[:pvp]
|
35
|
+
assert_nil @data[:pebit]
|
36
|
+
assert_nil @data[:lpa]
|
37
|
+
assert_nil @data[:vpa]
|
38
|
+
assert_nil @data[:net_margin]
|
39
|
+
assert_nil @data[:net_debt]
|
40
|
+
assert_nil @data[:net_assets]
|
41
|
+
assert_nil @data[:yearly_net_income]
|
42
|
+
assert_nil @data[:yearly_net_profit]
|
43
|
+
assert_nil @data[:quarterly_net_income]
|
44
|
+
assert_nil @data[:quarterly_net_profit]
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def invalid_content
|
50
|
+
'<html>'
|
51
|
+
end
|
52
|
+
|
53
|
+
def valid_content
|
54
|
+
File.open(File.expand_path('vale5.html', File.dirname(__FILE__) + '/data/')).read
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
class LocalFileFetcher
|
2
|
-
def initialize(dir_path, file_ext = '.html')
|
3
|
-
@dir_path = dir_path
|
4
|
-
@file_ext = file_ext
|
5
|
-
end
|
6
|
-
|
7
|
-
def fetch(urls)
|
8
|
-
response = {}
|
9
|
-
urls.each do |key, url|
|
10
|
-
path = @dir_path + "#{key}" + @file_ext
|
11
|
-
if File.readable?(path)
|
12
|
-
response[key] = File.read(path)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
response
|
16
|
-
end
|
17
|
-
end
|
1
|
+
class LocalFileFetcher
|
2
|
+
def initialize(dir_path, file_ext = '.html')
|
3
|
+
@dir_path = dir_path
|
4
|
+
@file_ext = file_ext
|
5
|
+
end
|
6
|
+
|
7
|
+
def fetch(urls)
|
8
|
+
response = {}
|
9
|
+
urls.each do |key, url|
|
10
|
+
path = @dir_path + "#{key}" + @file_ext
|
11
|
+
if File.readable?(path)
|
12
|
+
response[key] = File.read(path)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
response
|
16
|
+
end
|
17
|
+
end
|
data/test/output/.keep
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fundamentus_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinicius Pinto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -84,8 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
|
-
|
88
|
-
rubygems_version: 2.4.6
|
87
|
+
rubygems_version: 3.3.5
|
89
88
|
signing_key:
|
90
89
|
specification_version: 4
|
91
90
|
summary: Save brazilian stock data from the Fundamentus site in JSON format
|