Class: Nfe::Helpers::NfeKey
- Inherits:
-
Object
- Object
- Nfe::Helpers::NfeKey
- Defined in:
- lib/nfe/helpers/nfe_key.rb
Instance Attribute Summary collapse
-
#cnpj ⇒ Object
readonly
Returns the value of attribute cnpj.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#series ⇒ Object
readonly
Returns the value of attribute series.
-
#uf ⇒ Object
readonly
Returns the value of attribute uf.
Class Method Summary collapse
Instance Method Summary collapse
- #check_digit ⇒ Object
- #emission_kind ⇒ Object
-
#initialize(uf, date, cnpj, series, number, code) ⇒ NfeKey
constructor
A new instance of NfeKey.
- #key ⇒ Object
- #model ⇒ Object
- #month ⇒ Object
- #year ⇒ Object
Constructor Details
#initialize(uf, date, cnpj, series, number, code) ⇒ NfeKey
Returns a new instance of NfeKey.
16 17 18 19 20 21 22 23 |
# File 'lib/nfe/helpers/nfe_key.rb', line 16 def initialize(uf, date, cnpj, series, number, code) @uf = uf @date = date @cnpj = cnpj @series = series @number = number @code = code end |
Instance Attribute Details
#cnpj ⇒ Object (readonly)
Returns the value of attribute cnpj.
14 15 16 |
# File 'lib/nfe/helpers/nfe_key.rb', line 14 def cnpj @cnpj end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
14 15 16 |
# File 'lib/nfe/helpers/nfe_key.rb', line 14 def code @code end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
14 15 16 |
# File 'lib/nfe/helpers/nfe_key.rb', line 14 def number @number end |
#series ⇒ Object (readonly)
Returns the value of attribute series.
14 15 16 |
# File 'lib/nfe/helpers/nfe_key.rb', line 14 def series @series end |
#uf ⇒ Object (readonly)
Returns the value of attribute uf.
14 15 16 |
# File 'lib/nfe/helpers/nfe_key.rb', line 14 def uf @uf end |
Class Method Details
.parse(nfe_key) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/nfe/helpers/nfe_key.rb', line 25 def self.parse(nfe_key) uf = Helpers::UfHelper.acronym(nfe_key[0..1].to_i) year = nfe_key[2..3].to_i month = nfe_key[4..5].to_i cnpj = nfe_key[6..19] series = nfe_key[22..24].to_i number = nfe_key[25..33].to_i code = nfe_key[35..42].to_i date = Date.new(year, month, 1) new(uf, date, cnpj, series, number, code) rescue raise NfeKeyError.new(nfe_key) end |
Instance Method Details
#check_digit ⇒ Object
59 60 61 |
# File 'lib/nfe/helpers/nfe_key.rb', line 59 def check_digit generate_check_digit(key_without_check_digit, weights) end |
#emission_kind ⇒ Object
55 56 57 |
# File 'lib/nfe/helpers/nfe_key.rb', line 55 def emission_kind 1 end |
#key ⇒ Object
39 40 41 |
# File 'lib/nfe/helpers/nfe_key.rb', line 39 def key "#{key_without_check_digit}#{check_digit}" end |
#model ⇒ Object
51 52 53 |
# File 'lib/nfe/helpers/nfe_key.rb', line 51 def model 55 end |
#month ⇒ Object
47 48 49 |
# File 'lib/nfe/helpers/nfe_key.rb', line 47 def month @date.strftime("%m") end |
#year ⇒ Object
43 44 45 |
# File 'lib/nfe/helpers/nfe_key.rb', line 43 def year @date.strftime("%y") end |