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.
@@ -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
- stocks.each do |code, info|
13
- File.unlink(info[:json_path]) unless not File.exists?(info[:json_path])
14
- end
15
-
16
- html_fetcher = LocalFileFetcher.new(TEST_DIR + 'data/')
17
- file_manager = FileManager.new(TEST_DIR + 'output/')
18
- parser = FundamentusParser.new
19
-
20
- pages = FundamentusFetcher.new(html_fetcher).fetch(stocks.keys)
21
-
22
- pages.each do |key, content|
23
- file_manager.save(key + '.json', parser.parse(content).to_json)
24
- end
25
-
26
- stocks.each do |code, info|
27
- assert_equal info[:json], File.open(info[:json_path]).read
28
- end
29
-
30
- end
31
-
32
- private
33
-
34
- def petr4_json
35
- '{"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"}'
36
- end
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
- code = 'VALE5'
12
- args = { code => 'http://www.fundamentus.com.br/detalhes.php?papel=' + code }
13
- @url_fetcher.expect :fetch, nil, [args]
14
- @fundamentus_fetcher.fetch(code)
15
- end
16
-
17
- def test_fetching_page_with_array_of_codes
18
- stock_codes = ['VALE5', 'PETR4', 'ITUB4']
19
- args = {}
20
- stock_codes.each do |code|
21
- args[code] = 'http://www.fundamentus.com.br/detalhes.php?papel=' + code
22
- end
23
- @url_fetcher.expect :fetch, nil, [args]
24
- @fundamentus_fetcher.fetch(stock_codes)
25
- end
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
- load_valid_file
11
- assert_equal '5.365.300.000', @parsed[:share_count]
12
- assert_equal '158.169.000.000', @parsed[:market_cap]
13
- assert_equal '31/12/2013', @parsed[:last_processed]
14
- assert_equal '1.374,30', @parsed[:pl]
15
- assert_equal '1,07', @parsed[:pvp]
16
- assert_equal '3,43', @parsed[:pebit]
17
- assert_equal '0,02', @parsed[:lpa]
18
- assert_equal '27,65', @parsed[:vpa]
19
- assert_equal '-0,3%', @parsed[:net_margin]
20
- assert_equal '56.511.800.000', @parsed[:net_debt]
21
- assert_equal '148.346.000.000', @parsed[:net_assets]
22
- assert_equal '101.490.000.000', @parsed[:yearly_net_income]
23
- assert_equal '115.091.000', @parsed[:yearly_net_profit]
24
- assert_equal '28.626.200.000', @parsed[:quarterly_net_income]
25
- assert_equal '-14.867.100.000', @parsed[:quarterly_net_profit]
26
- end
27
-
28
- def test_parse_invalid_file
29
- load_invalid_file
30
- assert_nil @parsed[:share_count]
31
- assert_nil @parsed[:market_cap]
32
- assert_nil @parsed[:last_processed]
33
- assert_nil @parsed[:pl]
34
- assert_nil @parsed[:pvp]
35
- assert_nil @parsed[:pebit]
36
- assert_nil @parsed[:lpa]
37
- assert_nil @parsed[:vpa]
38
- assert_nil @parsed[:net_margin]
39
- assert_nil @parsed[:net_debt]
40
- assert_nil @parsed[:net_assets]
41
- assert_nil @parsed[:yearly_net_income]
42
- assert_nil @parsed[:yearly_net_profit]
43
- assert_nil @parsed[:quarterly_net_income]
44
- assert_nil @parsed[:quarterly_net_profit]
45
- end
46
-
47
- def load_valid_file
48
- @page = File.open(File.expand_path('vale5.html', File.dirname(__FILE__) + '/data/')).read
49
- @parsed = @parser.parse(@page)
50
- end
51
-
52
- def load_invalid_file
53
- @page = '<html>';
54
- @parsed = @parser.parse(@page)
55
- end
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.0
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: 2015-04-09 00:00:00.000000000 Z
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
- rubyforge_project:
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