Class: Correios::Pricefier::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/pricefier/helper.rb

Instance Method Summary collapse

Instance Method Details

#calculate_deadline_date(days, saturday, date = Date.today) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pricefier/helper.rb', line 13

def calculate_deadline_date(days, saturday, date = Date.today)
  if saturday
    days.to_i.times do
      date += 1.days
      date += 1.days if date.sunday?
    end
  else
    days.to_i.times do
      date += 1.days
      date += 1.days if deadline.sunday? || deadline.saturday?
    end
  end
  date
end

#convert_bool_to_string(bool) ⇒ Object



40
41
42
43
# File 'lib/pricefier/helper.rb', line 40

def convert_bool_to_string(bool)
  return 'S' if bool
  'N'
end

#convert_date_to_string(date) ⇒ Object



32
33
34
# File 'lib/pricefier/helper.rb', line 32

def convert_date_to_string(date)
  date.strftime('%d/%m/%Y')
end

#convert_string_to_bool(string) ⇒ Object



36
37
38
# File 'lib/pricefier/helper.rb', line 36

def convert_string_to_bool(string)
  string == 'S'
end

#convert_string_to_date(date) ⇒ Object



28
29
30
# File 'lib/pricefier/helper.rb', line 28

def convert_string_to_date(date)
  Date.strptime(date, '%d/%m/%Y')
end

#convert_string_to_float(string) ⇒ Object



45
46
47
48
# File 'lib/pricefier/helper.rb', line 45

def convert_string_to_float(string)
  string = string.tr(',', '.')
  string.to_f
end

#format_service_codes(services) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/pricefier/helper.rb', line 63

def format_service_codes(services)
  services_string = ''
  services.each do |service|
    services_string += "#{service},"
  end
  services_string
end

#namespacesObject



6
7
8
9
10
11
# File 'lib/pricefier/helper.rb', line 6

def namespaces
  {
    'xmlns:soap' => 'http://www.w3.org/2003/05/soap-envelope',
    'xmlns:ns1' => 'http://tempuri.org/'
  }
end

#object_type(type) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pricefier/helper.rb', line 50

def object_type(type)
  case type
  when :letter_envelope
    3
  when :box
    1
  when :prism
    1
  when :cylinder
    2
  end
end