Class: Correios::Frete::Servico
- Inherits:
-
Object
- Object
- Correios::Frete::Servico
- Includes:
- SAXMachine
- Defined in:
- lib/correios/frete/servico.rb
Constant Summary collapse
- AVAILABLE_SERVICES =
{ "04510" => { :type => :pac, :name => "PAC", :description => "PAC sem contrato" }, "41068" => { :type => :pac_com_contrato, :name => "PAC", :description => "PAC com contrato" }, "04669" => { :type => :pac_com_contrato_2, :name => "PAC", :description => "PAC com contrato" }, "41300" => { :type => :pac_gf, :name => "PAC GF", :description => "PAC para grandes formatos" }, "04014" => { :type => :sedex, :name => "SEDEX", :description => "SEDEX sem contrato" }, "40045" => { :type => :sedex_a_cobrar, :name => "SEDEX a Cobrar", :description => "SEDEX a Cobrar, sem contrato" }, "40126" => { :type => :sedex_a_cobrar_com_contrato, :name => "SEDEX a Cobrar", :description => "SEDEX a Cobrar, com contrato" }, "40215" => { :type => :sedex_10, :name => "SEDEX 10", :description => "SEDEX 10, sem contrato" }, "40290" => { :type => :sedex_hoje, :name => "SEDEX Hoje", :description => "SEDEX Hoje, sem contrato" }, "40096" => { :type => :sedex_com_contrato_1, :name => "SEDEX", :description => "SEDEX com contrato" }, "40436" => { :type => :sedex_com_contrato_2, :name => "SEDEX", :description => "SEDEX com contrato" }, "40444" => { :type => :sedex_com_contrato_3, :name => "SEDEX", :description => "SEDEX com contrato" }, "40568" => { :type => :sedex_com_contrato_4, :name => "SEDEX", :description => "SEDEX com contrato" }, "40606" => { :type => :sedex_com_contrato_5, :name => "SEDEX", :description => "SEDEX com contrato" }, "04162" => { :type => :sedex_com_contrato_6, :name => "SEDEX", :description => "SEDEX com contrato" }, "81019" => { :type => :e_sedex, :name => "e-SEDEX", :description => "e-SEDEX, com contrato" }, "81027" => { :type => :e_sedex_prioritario, :name => "e-SEDEX", :description => "e-SEDEX Prioritário, com contrato" }, "81035" => { :type => :e_sedex_express, :name => "e-SEDEX", :description => "e-SEDEX Express, com contrato" }, "81868" => { :type => :e_sedex_grupo_1, :name => "e-SEDEX", :description => "(Grupo 1) e-SEDEX, com contrato" }, "81833" => { :type => :e_sedex_grupo_2, :name => "e-SEDEX", :description => "(Grupo 2) e-SEDEX, com contrato" }, "81850" => { :type => :e_sedex_grupo_3, :name => "e-SEDEX", :description => "(Grupo 3) e-SEDEX, com contrato" } }.freeze
Instance Attribute Summary collapse
-
#descricao ⇒ Object
readonly
Returns the value of attribute descricao.
-
#nome ⇒ Object
readonly
Returns the value of attribute nome.
-
#tipo ⇒ Object
readonly
Returns the value of attribute tipo.
Class Method Summary collapse
Instance Method Summary collapse
- #error? ⇒ Boolean (also: #erro?)
- #original_parse ⇒ Object
- #parse(xml_text) ⇒ Object
- #success? ⇒ Boolean (also: #sucesso?)
Instance Attribute Details
#descricao ⇒ Object (readonly)
Returns the value of attribute descricao.
43 44 45 |
# File 'lib/correios/frete/servico.rb', line 43 def descricao @descricao end |
#nome ⇒ Object (readonly)
Returns the value of attribute nome.
43 44 45 |
# File 'lib/correios/frete/servico.rb', line 43 def nome @nome end |
#tipo ⇒ Object (readonly)
Returns the value of attribute tipo.
43 44 45 |
# File 'lib/correios/frete/servico.rb', line 43 def tipo @tipo end |
Class Method Details
.code_from_type(type) ⇒ Object
72 73 74 75 |
# 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 |
Instance Method Details
#error? ⇒ Boolean Also known as: erro?
67 68 69 |
# File 'lib/correios/frete/servico.rb', line 67 def error? !success? end |
#original_parse ⇒ Object
45 |
# File 'lib/correios/frete/servico.rb', line 45 alias_method :original_parse, :parse |
#parse(xml_text) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 |
#success? ⇒ Boolean Also known as: sucesso?
62 63 64 |
# File 'lib/correios/frete/servico.rb', line 62 def success? valor > 0.0 end |