Module: BrazilianUtils::CFOPUtils
- Defined in:
- lib/brazilian-utils/cfop-utils.rb
Overview
Utilities for the CFOP (Código Fiscal de Operações e Prestações) table, the consolidated Anexo II of Convênio SINIEF s/nº 1970 in force. Only operable codes are included (group/subgroup headings are excluded).
Constant Summary collapse
- DATA_FILE =
File.join(File.dirname(__FILE__), 'data', 'cfop.json')
Class Method Summary collapse
-
.get(value) ⇒ Hash?
Looks a CFOP code up and returns its code and description.
-
.is_valid(value) ⇒ Boolean
(also: valid?)
Checks whether a CFOP code exists in the official table (group and subgroup headings are not operable codes and are rejected).
-
.parse(value) ⇒ String
Removes CFOP formatting and keeps only digits, capped to 4 digits (nothing is padded).
Class Method Details
.get(value) ⇒ Hash?
Looks a CFOP code up and returns its code and description.
55 56 57 58 59 60 61 |
# File 'lib/brazilian-utils/cfop-utils.rb', line 55 def self.get(value) code = normalize(value) return nil unless code description = load_data[code] description && { code: code, description: description } end |
.is_valid(value) ⇒ Boolean Also known as: valid?
Checks whether a CFOP code exists in the official table (group and subgroup headings are not operable codes and are rejected).
40 41 42 43 44 45 |
# File 'lib/brazilian-utils/cfop-utils.rb', line 40 def self.is_valid(value) code = normalize(value) return false unless code load_data.key?(code) end |
.parse(value) ⇒ String
Removes CFOP formatting and keeps only digits, capped to 4 digits (nothing is padded).
68 69 70 71 72 |
# File 'lib/brazilian-utils/cfop-utils.rb', line 68 def self.parse(value) return '' unless value.is_a?(String) || value.is_a?(Integer) value.to_s.gsub(/\D/, '')[0, 4] end |