baa_chan 0.0.1 → 0.0.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 +4 -4
- data/lib/baa_chan/layout.rb +19 -7
- data/lib/baa_chan/layouts/clear.yml +20 -8
- data/lib/baa_chan/layouts/genial.yml +20 -8
- data/lib/baa_chan/layouts/singulare.yml +18 -8
- data/lib/baa_chan/parser.rb +7 -4
- data/lib/baa_chan/reader.rb +9 -11
- metadata +5 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: ad4af573c534fad3d66d4a911a0fbe8aa686e762931585417707e4b43a3f6e10
         | 
| 4 | 
            +
              data.tar.gz: 5315df0e4cd0089e2aa72a95ae38be5ac5aa9e44be98901944e333f6e7f9f9d2
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: b2e3a5f740bb75ece4b2d029a0eb13a14d7a14b4fd7dee8b604034aa1fb35f1393415ac9ee6cac2be69407569a7e86397c4757cf839fdc03e06926ce418204e7
         | 
| 7 | 
            +
              data.tar.gz: dbcd2a27cfbd79ec0ab5e050f69fed9b9488785c4b68a4c0320677e1e1620f8f954b3d80728bd265796ac5dc06d19d4b7b986c137350b60b5623e20b1c8061b8
         | 
    
        data/lib/baa_chan/layout.rb
    CHANGED
    
    | @@ -8,24 +8,36 @@ class Layout | |
| 8 8 | 
             
              end
         | 
| 9 9 |  | 
| 10 10 | 
             
              def attributes
         | 
| 11 | 
            -
                @attributes ||= YAML.safe_load( | 
| 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 =  | 
| 19 | 
            -
                 | 
| 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 | 
            -
             | 
| 28 | 
            +
              def trade
         | 
| 29 | 
            +
                @trade ||= attributes['trades']
         | 
| 22 30 | 
             
              end
         | 
| 23 31 |  | 
| 24 32 | 
             
              def trade_prefix
         | 
| 25 | 
            -
                 | 
| 33 | 
            +
                trade['prefix']
         | 
| 26 34 | 
             
              end
         | 
| 27 35 |  | 
| 28 | 
            -
              def  | 
| 29 | 
            -
                 | 
| 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 | 
            -
             | 
| 12 | 
            -
               | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 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 | 
            -
             | 
| 12 | 
            -
               | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 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 | 
            -
             | 
| 12 | 
            -
               | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 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
         | 
    
        data/lib/baa_chan/parser.rb
    CHANGED
    
    | @@ -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. | 
| 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. | 
| 70 | 
            +
                  @trade_line.split(/\s{2,}/)[@layout.trade_index(@asset)]
         | 
| 68 71 | 
             
                end
         | 
| 69 72 |  | 
| 70 73 | 
             
                def quantity
         | 
| 71 | 
            -
                  @trade_line. | 
| 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. | 
| 78 | 
            +
                  @trade_line.scan(Regexp.new(@layout.trade_regexp(@asset)))[0].gsub(',', '.').to_f
         | 
| 76 79 | 
             
                end
         | 
| 77 80 | 
             
              end
         | 
| 78 81 |  | 
    
        data/lib/baa_chan/reader.rb
    CHANGED
    
    | @@ -35,17 +35,15 @@ module BaaChan | |
| 35 35 | 
             
                end
         | 
| 36 36 |  | 
| 37 37 | 
             
                def detect_layout(lines)
         | 
| 38 | 
            -
                   | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 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. | 
| 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- | 
| 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:// | 
| 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:
         |