class Correios::Frete::Calculador

Constants

DEFAULT_OPTIONS

Attributes

altura[W]
aviso_recebimento[RW]
cep_destino[RW]
cep_origem[RW]
codigo_empresa[RW]
comprimento[W]
diametro[RW]
encomenda[RW]
formato[W]
largura[W]
mao_propria[RW]
peso[W]
senha[RW]
valor_declarado[RW]

Public Class Methods

new(options = {}) { |self| ... } click to toggle source
# File lib/correios/frete/calculador.rb, line 22
def initialize(options = {})
  DEFAULT_OPTIONS.merge(options).each do |attr, value|
    self.send("#{attr}=", value)
  end

  yield self if block_given?
end

Public Instance Methods

calcular(*service_types) click to toggle source
# File lib/correios/frete/calculador.rb, line 36
def calcular(*service_types)
  response = web_service(service_types).request!
  services = parser.servicos(response)

  if service_types.size == 1
    services.values.first
  else
    services
  end
end
Also aliased as: calculate
calculate(*service_types)
Alias for: calcular
method_missing(method_name, *args) click to toggle source
Calls superclass method
# File lib/correios/frete/calculador.rb, line 48
def method_missing(method_name, *args)
  return calcular($2.to_sym) if method_name.to_s =~ /^(calcular|calculate)_(.*)/ && Correios::Frete::Servico.code_from_type($2.to_sym)
  super
end
respond_to?(method_name) click to toggle source
Calls superclass method
# File lib/correios/frete/calculador.rb, line 53
def respond_to?(method_name)
  return true if method_name.to_s =~ /^(calcular|calculate)_(.*)/ && Correios::Frete::Servico.code_from_type($2.to_sym)
  super
end

Private Instance Methods

parser() click to toggle source
# File lib/correios/frete/calculador.rb, line 64
def parser
  @parser ||= Correios::Frete::Parser.new
end
web_service(service_types) click to toggle source
# File lib/correios/frete/calculador.rb, line 60
def web_service(service_types)
  Correios::Frete::WebService.new(self, service_types)
end