bancos_brasileiros_data 6.3.123

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.
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BancosBrasileiros
4
+ # Overwritten by the publish-rubygems workflow with the release tag version.
5
+ VERSION = "6.3.123"
6
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require_relative "bancos_brasileiros_data/version"
5
+
6
+ # Brazilian commercial banks list, backed by data/bancos.json.
7
+ #
8
+ # Every bank is returned as a frozen Hash using the same keys as the JSON
9
+ # file ("COMPE", "ISPB", "Document", "LongName", "ShortName", ...).
10
+ module BancosBrasileiros
11
+ DATA_PATH = File.expand_path("../../data/bancos.json", __dir__)
12
+
13
+ class << self
14
+ # All banks, parsed once and cached.
15
+ def all_banks
16
+ @all_banks ||= load_data
17
+ end
18
+
19
+ # Parses data/bancos.json (which starts with a UTF-8 BOM).
20
+ def load_data
21
+ deep_freeze(JSON.parse(File.read(DATA_PATH, mode: "r:bom|utf-8")))
22
+ end
23
+
24
+ # Finds a bank by its COMPE code. Accepts "1", "001" or 1.
25
+ def find_bank_by_compe(compe)
26
+ code = compe.to_s.strip
27
+ return nil if code.empty?
28
+
29
+ code = code.rjust(3, "0")
30
+ all_banks.find { |bank| bank["COMPE"] == code }
31
+ end
32
+ alias find_bank_by_codigo_compe find_bank_by_compe
33
+
34
+ # Finds a bank by its ISPB code. Accepts "0", "00000000" or 0.
35
+ def find_bank_by_ispb(ispb)
36
+ code = ispb.to_s.strip
37
+ return nil if code.empty?
38
+
39
+ code = code.rjust(8, "0")
40
+ all_banks.find { |bank| bank["ISPB"] == code }
41
+ end
42
+
43
+ # Finds a bank by its CNPJ, with or without punctuation.
44
+ def find_bank_by_document(document)
45
+ digits = document.to_s.gsub(/\D/, "")
46
+ return nil if digits.empty?
47
+
48
+ all_banks.find { |bank| bank["Document"].to_s.gsub(/\D/, "") == digits }
49
+ end
50
+
51
+ def find_banks_by_network(network)
52
+ all_banks.select { |bank| bank["Network"] == network }
53
+ end
54
+
55
+ def find_banks_by_type(bank_type)
56
+ all_banks.select { |bank| bank["Type"] == bank_type }
57
+ end
58
+
59
+ def find_banks_by_pix_type(pix_type)
60
+ all_banks.select { |bank| bank["PixType"] == pix_type }
61
+ end
62
+
63
+ # Case-insensitive search on LongName and ShortName.
64
+ def search(term)
65
+ needle = term.to_s.strip.downcase
66
+ return [] if needle.empty?
67
+
68
+ all_banks.select do |bank|
69
+ bank["LongName"].to_s.downcase.include?(needle) ||
70
+ bank["ShortName"].to_s.downcase.include?(needle)
71
+ end
72
+ end
73
+
74
+ private
75
+
76
+ def deep_freeze(value)
77
+ case value
78
+ when Hash then value.each_value { |v| deep_freeze(v) }
79
+ when Array then value.each { |v| deep_freeze(v) }
80
+ else value
81
+ end
82
+ value.freeze
83
+ end
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bancos_brasileiros_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 6.3.123
5
+ platform: ruby
6
+ authors:
7
+ - Guilherme Branco Stracini
8
+ - Elton Santos
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2026-11-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Brazilian commercial banks list (COMPE, ISPB, CNPJ, PIX and more), updated
15
+ daily from official sources.
16
+ email:
17
+ - opensource@straccini.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENSE
23
+ - README.md
24
+ - data/bancos.json
25
+ - ruby/lib/bancos_brasileiros_data.rb
26
+ - ruby/lib/bancos_brasileiros_data/version.rb
27
+ homepage: https://github.com/guibranco/BancosBrasileiros
28
+ licenses:
29
+ - Unlicense
30
+ metadata:
31
+ homepage_uri: https://github.com/guibranco/BancosBrasileiros
32
+ source_code_uri: https://github.com/guibranco/BancosBrasileiros
33
+ changelog_uri: https://github.com/guibranco/BancosBrasileiros/blob/main/CHANGELOG.md
34
+ bug_tracker_uri: https://github.com/guibranco/BancosBrasileiros/issues
35
+ rubygems_mfa_required: 'true'
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - ruby/lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 2.6.0
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.5.22
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: "\U0001F1E7\U0001F1F7 \U0001F3E6 \U0001F4CB Brazilian commercial banks list"
55
+ test_files: []