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 72 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
error?()
click to toggle source
# File lib/correios/frete/servico.rb, line 67 def error? !success? end
Also aliased as: erro?
parse(xml_text)
click to toggle source
# File lib/correios/frete/servico.rb, line 47 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 62 def success? valor > 0.0 end
Also aliased as: sucesso?
Private Instance Methods
cast_to_boolean!(*attributes)
click to toggle source
# File lib/correios/frete/servico.rb, line 92 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 79 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 86 def cast_to_int!(*attributes) attributes.each do |attr| instance_variable_set("@#{attr}", send(attr).to_i) end end