Class: Jamef::Tax
- Inherits:
-
Object
- Object
- Jamef::Tax
- 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
-
#cep ⇒ Object
Returns the value of attribute cep.
-
#cnpj ⇒ Object
Returns the value of attribute cnpj.
-
#cubage ⇒ Object
Returns the value of attribute cubage.
-
#region ⇒ Object
Returns the value of attribute region.
-
#uf ⇒ Object
Returns the value of attribute uf.
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(cubage = nil, cnpj = nil, region = nil, cep = nil, uf = nil) ⇒ Tax
constructor
A new instance of Tax.
- #params ⇒ Object
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
#cep ⇒ Object
Returns the value of attribute cep.
3 4 5 |
# File 'lib/jamef/tax.rb', line 3 def cep @cep end |
#cnpj ⇒ Object
Returns the value of attribute cnpj.
3 4 5 |
# File 'lib/jamef/tax.rb', line 3 def cnpj @cnpj end |
#cubage ⇒ Object
Returns the value of attribute cubage.
3 4 5 |
# File 'lib/jamef/tax.rb', line 3 def cubage @cubage end |
#region ⇒ Object
Returns the value of attribute region.
3 4 5 |
# File 'lib/jamef/tax.rb', line 3 def region @region end |
#uf ⇒ Object
Returns the value of attribute uf.
3 4 5 |
# File 'lib/jamef/tax.rb', line 3 def uf @uf end |
Instance Method Details
#get ⇒ Object
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 |
#params ⇒ Object
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 |