Class: Nfcom::Models::Fatura::CodigoDeBarras
- Inherits:
-
Object
- Object
- Nfcom::Models::Fatura::CodigoDeBarras
- Defined in:
- lib/nfcom/models/fatura/codigo_de_barras.rb,
lib/nfcom/models/fatura/codigo_de_barras/formato_44.rb
Defined Under Namespace
Classes: Formato44
Instance Attribute Summary collapse
-
#valor ⇒ Object
readonly
Returns the value of attribute valor.
Instance Method Summary collapse
- #formato ⇒ Object
-
#initialize(valor) ⇒ CodigoDeBarras
constructor
A new instance of CodigoDeBarras.
- #linha_digitavel ⇒ Object
- #tamanho ⇒ Object
- #valido? ⇒ Boolean
Constructor Details
#initialize(valor) ⇒ CodigoDeBarras
Returns a new instance of CodigoDeBarras.
9 10 11 12 |
# File 'lib/nfcom/models/fatura/codigo_de_barras.rb', line 9 def initialize(valor) @valor = valor.to_s.gsub(/\D/, '') validar! end |
Instance Attribute Details
#valor ⇒ Object (readonly)
Returns the value of attribute valor.
7 8 9 |
# File 'lib/nfcom/models/fatura/codigo_de_barras.rb', line 7 def valor @valor end |
Instance Method Details
#formato ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/nfcom/models/fatura/codigo_de_barras.rb', line 18 def formato case tamanho when 44 then :formato_44 when 48 then :formato_48 else :desconhecido end end |
#linha_digitavel ⇒ Object
26 27 28 |
# File 'lib/nfcom/models/fatura/codigo_de_barras.rb', line 26 def linha_digitavel handler.linha_digitavel end |
#tamanho ⇒ Object
14 15 16 |
# File 'lib/nfcom/models/fatura/codigo_de_barras.rb', line 14 def tamanho valor.length end |
#valido? ⇒ Boolean
30 31 32 33 34 |
# File 'lib/nfcom/models/fatura/codigo_de_barras.rb', line 30 def valido? true rescue ArgumentError false end |