Class: Nfe::Helpers::NfeKey

Inherits:
Object
  • Object
show all
Defined in:
lib/nfe/helpers/nfe_key.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#cnpjObject (readonly)

Returns the value of attribute cnpj.



14
15
16
# File 'lib/nfe/helpers/nfe_key.rb', line 14

def cnpj
  @cnpj
end

#codeObject (readonly)

Returns the value of attribute code.



14
15
16
# File 'lib/nfe/helpers/nfe_key.rb', line 14

def code
  @code
end

#numberObject (readonly)

Returns the value of attribute number.



14
15
16
# File 'lib/nfe/helpers/nfe_key.rb', line 14

def number
  @number
end

#seriesObject (readonly)

Returns the value of attribute series.



14
15
16
# File 'lib/nfe/helpers/nfe_key.rb', line 14

def series
  @series
end

#ufObject (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_digitObject



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_kindObject



55
56
57
# File 'lib/nfe/helpers/nfe_key.rb', line 55

def emission_kind
  1
end

#keyObject



39
40
41
# File 'lib/nfe/helpers/nfe_key.rb', line 39

def key
  "#{key_without_check_digit}#{check_digit}"
end

#modelObject



51
52
53
# File 'lib/nfe/helpers/nfe_key.rb', line 51

def model
  55
end

#monthObject



47
48
49
# File 'lib/nfe/helpers/nfe_key.rb', line 47

def month
  @date.strftime("%m")
end

#yearObject



43
44
45
# File 'lib/nfe/helpers/nfe_key.rb', line 43

def year
  @date.strftime("%y")
end