class Correios::Frete::Servico

Constants

AVAILABLE_SERVICES

Attributes

descricao[R]
nome[R]
tipo[R]

Public Class Methods

code_from_type(type) click to toggle source
# File lib/correios/frete/servico.rb, line 70
def self.code_from_type(type)
  # I don't use select method for Ruby 1.8.7 compatibility.
  AVAILABLE_SERVICES.map { |key, value| key if value[:type] == type }.compact.first
end

Public Instance Methods

erro?()
Alias for: error?
error?() click to toggle source
# File lib/correios/frete/servico.rb, line 65
def error?
  !success?
end
Also aliased as: erro?
original_parse(xml_text)
Alias for: parse
parse(xml_text) click to toggle source
# File lib/correios/frete/servico.rb, line 45
def parse(xml_text)
  original_parse xml_text

  if AVAILABLE_SERVICES[codigo]
    @tipo = AVAILABLE_SERVICES[codigo][:type]
    @nome = AVAILABLE_SERVICES[codigo][:name]
    @descricao = AVAILABLE_SERVICES[codigo][:description]
  end

  cast_to_float! :valor, :valor_mao_propria, :valor_aviso_recebimento, :valor_valor_declarado
  cast_to_int! :prazo_entrega
  cast_to_boolean! :entrega_domiciliar, :entrega_sabado
  self
end
Also aliased as: original_parse
success?() click to toggle source
# File lib/correios/frete/servico.rb, line 60
def success?
  valor > 0.0
end
Also aliased as: sucesso?
sucesso?()
Alias for: success?

Private Instance Methods

cast_to_boolean!(*attributes) click to toggle source
# File lib/correios/frete/servico.rb, line 90
def cast_to_boolean!(*attributes)
  attributes.each do |attr|
    instance_variable_set("@#{attr}", send(attr) == "S")
  end
end
cast_to_float!(*attributes) click to toggle source
# File lib/correios/frete/servico.rb, line 77
def cast_to_float!(*attributes)
  attributes.each do |attr|
    value = send(attr).to_s.gsub(".", "").gsub("," ,".")
    instance_variable_set("@#{attr}", value.to_f)
  end
end
cast_to_int!(*attributes) click to toggle source
# File lib/correios/frete/servico.rb, line 84
def cast_to_int!(*attributes)
  attributes.each do |attr|
    instance_variable_set("@#{attr}", send(attr).to_i)
  end
end