Module: BrazilianUtils::CSOSNUtils

Defined in:
lib/brazilian-utils/csosn-utils.rb

Overview

Utilities for the CSOSN (Código de Situação da Operação no Simples Nacional) table (Ajuste SINIEF 07/2005).

Constant Summary collapse

DATA_FILE =
File.join(File.dirname(__FILE__), 'data', 'csosn.json')

Class Method Summary collapse

Class Method Details

.get_description(value) ⇒ String?

Looks up the description of a CSOSN code.

Parameters:

  • value (String, Integer)

Returns:

  • (String, nil)


40
41
42
43
44
45
46
# File 'lib/brazilian-utils/csosn-utils.rb', line 40

def self.get_description(value)
  return nil if value.nil?

  str = value.to_s.strip
  row = load_data.find { |r| r['code'] == str }
  row && row['description']
end

.is_valid(value) ⇒ Boolean Also known as: valid?

Checks whether a value is one of the 10 official CSOSN codes.

A CSOSN has no printed grouping/mask, so a value with any separator is rejected.

Parameters:

  • value (String, Integer)

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
# File 'lib/brazilian-utils/csosn-utils.rb', line 23

def self.is_valid(value)
  return false if value.nil?

  str = value.to_s.strip
  return false unless str.match?(/\A\d{3}\z/)

  load_data.any? { |row| row['code'] == str }
end

.list ⇒ Array<Hash>

Returns all 10 official CSOSN entries.

Returns:

  • (Array<Hash>)


51
52
53
# File 'lib/brazilian-utils/csosn-utils.rb', line 51

def self.list
  load_data.map { |row| { code: row['code'], description: row['description'] } }
end