baa_chan 0.0.1 → 0.0.2

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
  SHA256:
3
- metadata.gz: 6dd4992c1495048ce9123656452c1d9e2ed8ce3dffd2c7f070172c958f748cca
4
- data.tar.gz: b6a55877a52d39e01aeb3bb6f11d54a6f7f9a86e5622b70ba4e82e13e1302701
3
+ metadata.gz: ad4af573c534fad3d66d4a911a0fbe8aa686e762931585417707e4b43a3f6e10
4
+ data.tar.gz: 5315df0e4cd0089e2aa72a95ae38be5ac5aa9e44be98901944e333f6e7f9f9d2
5
5
  SHA512:
6
- metadata.gz: 392c751ceccd693dfb2a85d6140b69c8d1bfea4f08088917f8de8e0965deef3234b839aaba431a35ea996041cf0c4a50932b3353039e184cfda1a3b2fd178869
7
- data.tar.gz: 62c4a801ea57f5ff746a3edec50458ae18ad4e3ca8d01330bbdbf259ebe3d4eb3dd7132b4e46e654807558c6fe2aafdf77543c7f1d768c9f3d9c7524c96dc5fb
6
+ metadata.gz: b2e3a5f740bb75ece4b2d029a0eb13a14d7a14b4fd7dee8b604034aa1fb35f1393415ac9ee6cac2be69407569a7e86397c4757cf839fdc03e06926ce418204e7
7
+ data.tar.gz: dbcd2a27cfbd79ec0ab5e050f69fed9b9488785c4b68a4c0320677e1e1620f8f954b3d80728bd265796ac5dc06d19d4b7b986c137350b60b5623e20b1c8061b8
@@ -8,24 +8,36 @@ class Layout
8
8
  end
9
9
 
10
10
  def attributes
11
- @attributes ||= YAML.safe_load(File.read(File.join(LAYOUTS_PATH, "#{@broker}.yml")))
11
+ @attributes ||= YAML.safe_load(
12
+ File.read(File.join(LAYOUTS_PATH, "#{@broker}.yml")), aliases: true
13
+ )
12
14
  end
13
15
 
14
16
  def line
15
17
  attributes[caller_locations.first.label]['line'].to_i
16
18
  end
17
19
 
18
- def index(attr_name = nil)
19
- attr = attr_name || caller_locations.first.label
20
+ def index(attr_name = caller_locations.first.label)
21
+ attributes[attr_name]['index'].to_i
22
+ end
23
+
24
+ def regexp_for(attr)
25
+ attributes[attr]['regexp']
26
+ end
20
27
 
21
- attributes[attr]['index'].to_i
28
+ def trade
29
+ @trade ||= attributes['trades']
22
30
  end
23
31
 
24
32
  def trade_prefix
25
- attributes['trades']['prefix']
33
+ trade['prefix']
26
34
  end
27
35
 
28
- def regexp_for(attr)
29
- attributes[attr]['regexp']
36
+ def trade_index(asset)
37
+ trade[asset][caller_locations.first.label]['index'].to_i
38
+ end
39
+
40
+ def trade_regexp(asset)
41
+ trade[asset][caller_locations.first.label]['regexp']
30
42
  end
31
43
  end
@@ -6,16 +6,28 @@ trade_confirmation_number:
6
6
  trade_date:
7
7
  line: 2
8
8
  index: 2
9
+
9
10
  trades:
10
11
  prefix: 1-BOVESPA
11
- operation:
12
- index: 1
13
- ticker:
14
- index: 3
15
- quantity:
16
- index: 7
17
- price:
18
- index: 8
12
+
13
+ default: &default
14
+ operation:
15
+ index: 1
16
+ ticker:
17
+ index: 2
18
+ quantity:
19
+ regexp: \s\d{1,3}(?:\.\d+{3})*\s
20
+ price:
21
+ regexp: \s{2,}\d{1,3}(?:\.\d{3})*,\d{2,}\s{2,}
22
+
23
+ stock:
24
+ <<: *default
25
+
26
+ option:
27
+ <<: *default
28
+ ticker:
29
+ index: 4
30
+
19
31
  clearing_fee:
20
32
  regexp: .*Taxa de liquidação.*
21
33
  index: 7
@@ -6,16 +6,28 @@ trade_confirmation_number:
6
6
  trade_date:
7
7
  line: 2
8
8
  index: 2
9
+
9
10
  trades:
10
11
  prefix: 1-BOVESPA
11
- operation:
12
- index: 1
13
- ticker:
14
- index: 3
15
- quantity:
16
- index: 6
17
- price:
18
- index: 7
12
+
13
+ default: &default
14
+ operation:
15
+ index: 1
16
+ ticker:
17
+ index: 3
18
+ quantity:
19
+ regexp: \s\d{1,3}(?:\.\d+{3})*\s
20
+ price:
21
+ regexp: \s{2,}\d{1,3}(?:\.\d{3})*,\d{2,}\s{2,}
22
+
23
+ stock:
24
+ <<: *default
25
+
26
+ option:
27
+ <<: *default
28
+ ticker:
29
+ index: 4
30
+
19
31
  clearing_fee:
20
32
  regexp: .*Taxa de liquidação.*
21
33
  index: 7
@@ -6,16 +6,26 @@ trade_confirmation_number:
6
6
  trade_date:
7
7
  line: 2
8
8
  index: 2
9
+
9
10
  trades:
10
11
  prefix: BM&FBOVESPA S/A.
11
- operation:
12
- index: 2
13
- ticker:
14
- index: 6
15
- quantity:
16
- index: 9
17
- price:
18
- index: 10
12
+
13
+ default: &default
14
+ operation:
15
+ index: 2
16
+ ticker:
17
+ index: 4
18
+ quantity:
19
+ regexp: \s\d{1,3}(?:\.\d+{3})*\s
20
+ price:
21
+ regexp: \s{2,}\d{1,3}(?:\.\d{3})*,\d{2,}\s{2,}
22
+
23
+ stock:
24
+ <<: *default
25
+
26
+ option:
27
+ <<: *default
28
+
19
29
  clearing_fee:
20
30
  regexp: .*Taxa de Liquidação.*
21
31
  index: 7
@@ -6,6 +6,7 @@ require 'baa_chan/costs'
6
6
  require 'date'
7
7
  require 'yaml'
8
8
 
9
+ require 'pry-byebug'
9
10
  module BaaChan
10
11
  class CostsParserError < StandardError; end
11
12
 
@@ -52,6 +53,8 @@ module BaaChan
52
53
  @lines.each_with_object([]) do |line, trades|
53
54
  next unless line.include? @layout.trade_prefix
54
55
 
56
+ @asset = line.include?('OPCAO') ? 'option' : 'stock'
57
+
55
58
  @trade_line = line
56
59
  trades << Trade.new(operation, ticker, quantity, price)
57
60
  end
@@ -60,19 +63,19 @@ module BaaChan
60
63
  private
61
64
 
62
65
  def operation
63
- @trade_line.split[@layout.index] == 'V' ? 'Sell' : 'Buy'
66
+ @trade_line.split[@layout.trade_index(@asset)] == 'V' ? 'Sell' : 'Buy'
64
67
  end
65
68
 
66
69
  def ticker
67
- @trade_line.split[@layout.index]
70
+ @trade_line.split(/\s{2,}/)[@layout.trade_index(@asset)]
68
71
  end
69
72
 
70
73
  def quantity
71
- @trade_line.split[@layout.index].to_i
74
+ @trade_line.scan(Regexp.new(@layout.trade_regexp(@asset)))[0].strip.gsub('.', '').to_i
72
75
  end
73
76
 
74
77
  def price
75
- @trade_line.split[@layout.index].gsub(',', '.').to_f
78
+ @trade_line.scan(Regexp.new(@layout.trade_regexp(@asset)))[0].gsub(',', '.').to_f
76
79
  end
77
80
  end
78
81
 
@@ -35,17 +35,15 @@ module BaaChan
35
35
  end
36
36
 
37
37
  def detect_layout(lines)
38
- broker = if lines[3] == BROKER_LIST[:singulare]
39
- 'singulare'
40
- elsif lines[4] == BROKER_LIST[:genial]
41
- 'genial'
42
- elsif lines[4] == BROKER_LIST[:clear]
43
- 'clear'
44
- else
45
- raise UnknownLayoutError
46
- end
47
-
48
- return broker
38
+ if lines[3] == BROKER_LIST[:singulare]
39
+ 'singulare'
40
+ elsif lines[4] == BROKER_LIST[:genial]
41
+ 'genial'
42
+ elsif lines[4] == BROKER_LIST[:clear]
43
+ 'clear'
44
+ else
45
+ raise UnknownLayoutError
46
+ end
49
47
  end
50
48
  end
51
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baa_chan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diogo Noda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-27 00:00:00.000000000 Z
11
+ date: 2021-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-byebug
@@ -74,10 +74,11 @@ files:
74
74
  - lib/baa_chan/reader.rb
75
75
  - lib/baa_chan/trade.rb
76
76
  - lib/baa_chan/trade_confirmation.rb
77
- homepage: https://rubygems.org/gems/baa_chan
77
+ homepage: https://github.com/diogonoda/baa_chan
78
78
  licenses:
79
79
  - MIT
80
- metadata: {}
80
+ metadata:
81
+ source_code_uri: https://github.com/diogonoda/baa_chan
81
82
  post_install_message:
82
83
  rdoc_options: []
83
84
  require_paths: