class Jamef::Params

Public Class Methods

new(*args) click to toggle source

validates :tiptra, :cnpjcpf, :munori, :estori, :segprod, :qtdvol, :peso, :valmer, :metro3, :cepdes, :filcot, presence: true

Calls superclass method
# File lib/jamef/params.rb, line 19
def initialize *args
  super
  
  raise ArgumentError, errors.full_messages.join("\n") unless self.valid?
  self
end

Public Instance Methods

delivery_hash() click to toggle source
# File lib/jamef/params.rb, line 44
def delivery_hash
  hash = {}
  hash.store(:tiptra, tiptra)
  hash.store(:munori, munori)
  hash.store(:estori, estori)
  hash.store(:cnpjcpf, cnpjcpf)
  hash.store(:segprod, segprod)
  hash.store(:cdatini, cdatini)
  hash.store(:chorini, chorini)
  hash.store(:cnpjdes, cnpjdes)
  hash.store(:cepdes, cepdes)
  hash
end
freight_hash() click to toggle source
# File lib/jamef/params.rb, line 26
def freight_hash
  hash = {}
  hash.store(:tiptra, tiptra)
  hash.store(:cnpjcpf, cnpjcpf)
  hash.store(:munori, munori)
  hash.store(:estori, estori)
  hash.store(:segprod, segprod)
  hash.store(:qtdvol, qtdvol)
  hash.store(:peso, peso)
  hash.store(:valmer, valmer)
  hash.store(:metro3, metro3)
  hash.store(:cnpjdes, cnpjdes)
  hash.store(:filcot, filcot)
  hash.store(:cepdes, cepdes)
  hash.store(:contrib, contrib) if contrib?
  hash
end

Private Instance Methods

cdatini() click to toggle source

shipping date

# File lib/jamef/params.rb, line 130
def cdatini
  Jamef::Helper.format_date(shipping_in)
end
cepdes() click to toggle source

destination zip

# File lib/jamef/params.rb, line 106
def cepdes
  Jamef::Helper.format_zip(receiver.zip)
end
chorini() click to toggle source

shipping time

# File lib/jamef/params.rb, line 135
def chorini
  Jamef::Helper.format_time(shipping_in)
end
cnpjcpf() click to toggle source

document

# File lib/jamef/params.rb, line 66
def cnpjcpf
  Jamef::Helper.format_document(sender.document)
end
cnpjdes() click to toggle source

receiver document

# File lib/jamef/params.rb, line 125
def cnpjdes
  receiver.document.present? ? Jamef::Helper.format_document(receiver.document) : ''
end
contrib() click to toggle source

contrib! pays icms? tem inscrição estadual?

# File lib/jamef/params.rb, line 116
def contrib
  Jamef::Helper.format_boolean(receiver.contrib)
end
contrib?() click to toggle source
# File lib/jamef/params.rb, line 120
def contrib?
  receiver.contrib.present? and receiver.contrib
end
estori() click to toggle source

origin state

# File lib/jamef/params.rb, line 76
def estori
  Jamef::Helper.format_state(sender.state)
end
filcot() click to toggle source

jamef branch​

# File lib/jamef/params.rb, line 111
def filcot
  Jamef::Branch.find((branch || jamef_branch) || sender.jamef_branch).code
end
metro3() click to toggle source

package volume

# File lib/jamef/params.rb, line 101
def metro3
  Jamef::Helper.format_decimal(package.volume)
end
munori() click to toggle source

origin city

# File lib/jamef/params.rb, line 71
def munori
  Jamef::Helper.format_city(sender.city)
end
peso() click to toggle source

package weight

# File lib/jamef/params.rb, line 91
def peso
  Jamef::Helper.format_decimal(package.weight)
end
qtdvol() click to toggle source

volumes quantity

# File lib/jamef/params.rb, line 86
def qtdvol
  package.quantity || 1
end
segprod() click to toggle source

products type

# File lib/jamef/params.rb, line 81
def segprod
  Jamef::Package.type_map(package.type)
end
service_code() click to toggle source

service type map

# File lib/jamef/params.rb, line 140
def service_code
  value = {
    road: 1,
    air: 2
  }[service_type]
  value ? value : raise(ArgumentError, "Jamef #{service} service not found")
end
tiptra() click to toggle source

service type

# File lib/jamef/params.rb, line 61
def tiptra
  service_code
end
validate_package() click to toggle source
# File lib/jamef/params.rb, line 156
def validate_package
  errors.add(:package,'is not a valid Jamef::Package') unless (package.present? and package.valid?)
end
validate_receiver() click to toggle source
# File lib/jamef/params.rb, line 152
def validate_receiver
  errors.add(:receiver,'is not a valid Jamef::Receiver') unless (receiver.present? and receiver.valid?)
end
validate_sender() click to toggle source
# File lib/jamef/params.rb, line 148
def validate_sender
  errors.add(:sender,'is not a valid Jamef::Sender') unless (sender.present? and sender.valid?)
end
valmer() click to toggle source

package price

# File lib/jamef/params.rb, line 96
def valmer
  Jamef::Helper.format_decimal(package.price)
end