Class: Jamef::Tax

Inherits:
Object
  • Object
show all
Defined in:
lib/jamef/tax.rb

Constant Summary collapse

URL =
"http://www.jamef.com.br/internet/e-comerce/calculafrete_xml.asp"
XPATH =
"//transporte/frete"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cubage = nil, cnpj = nil, region = nil, cep = nil, uf = nil) ⇒ Tax

Returns a new instance of Tax.



8
9
10
11
12
13
14
# File 'lib/jamef/tax.rb', line 8

def initialize(cubage=nil, cnpj=nil, region=nil, cep=nil, uf=nil)
  @cubage = cubage
  @region = region.to_s
  @cnpj = cnpj
  @cep = cep
  @uf = uf
end

Instance Attribute Details

#cepObject

Returns the value of attribute cep.



3
4
5
# File 'lib/jamef/tax.rb', line 3

def cep
  @cep
end

#cnpjObject

Returns the value of attribute cnpj.



3
4
5
# File 'lib/jamef/tax.rb', line 3

def cnpj
  @cnpj
end

#cubageObject

Returns the value of attribute cubage.



3
4
5
# File 'lib/jamef/tax.rb', line 3

def cubage
  @cubage
end

#regionObject

Returns the value of attribute region.



3
4
5
# File 'lib/jamef/tax.rb', line 3

def region
  @region
end

#ufObject

Returns the value of attribute uf.



3
4
5
# File 'lib/jamef/tax.rb', line 3

def uf
  @uf
end

Instance Method Details

#getObject

Raises:



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jamef/tax.rb', line 16

def get
  raise Errors::NoClassArg.new if self.cubage.nil?

  node = Nokogiri::XML(get_xml)
  code = node.xpath("#{XPATH}/status").first.text
  
  if code.to_i == 2
    raise NoCarriage.new
  else
    node.xpath("#{XPATH}/valor").first.text.sub(",", ".").to_f
  end
end

#paramsObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jamef/tax.rb', line 29

def params
  {
    P_CIC_NEGC: self.cnpj,
    P_CEP: self.cep,
    P_VLR_CARG: cubage.price.total.to_i.to_s,
    P_PESO_KG: ("%.2f" % cubage.weight.total).gsub(".", ","),
    P_CUBG: ("%.3f" % cubage.total).gsub(".", ","),
    P_COD_REGN: self.region.to_s,
    P_UF: self.uf
  }
end