Class: Braspag::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/cbraspag/core/converter.rb

Class Method Summary collapse

Class Method Details

.decimal_to_string(value) ⇒ Object



3
4
5
6
# File 'lib/cbraspag/core/converter.rb', line 3

def self.decimal_to_string(value)
  #TODO: CHANGE ANOTHER FOR CONVERSION
  ("%.2f" % value.to_f).gsub('.', ',')
end

.hash_from_xml(document, map = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cbraspag/core/converter.rb', line 18

def self.hash_from_xml(document, map = {})
  document = Nokogiri::XML(document)

  map.each do |key, value|
    if value.is_a?(String) || value.nil?
      value = key if value.nil?

      new_value = document.search(value).first

      if new_value.nil?
        map[key] = nil
      else
        new_value = new_value.content.to_s
        map[key] = new_value unless new_value == ""
        map[key] = nil if new_value == ""
      end

    elsif value.is_a?(Proc)
      map[key] = value.call(document)
    end
  end

  map
end

.payment_method_name?(code) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/cbraspag/core/converter.rb', line 43

def self.payment_method_name?(code)
  Braspag::PAYMENT_METHOD.key(code.to_s.to_i)
end

.payment_method_type?(code) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cbraspag/core/converter.rb', line 47

def self.payment_method_type?(code)
  key = Braspag::PAYMENT_METHOD.key(code.to_s.to_i)
  return nil if key.nil?
  if key.match(/billet_/)
    :billet
  elsif key.match(/eft_/)
    :eft
  else
    :credit_card
  end
end

.status_name?(code) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/cbraspag/core/converter.rb', line 59

def self.status_name?(code)
  Braspag::STATUS_PAYMENT.key(code.to_s.to_i)
end

.string_to_decimal(value, mode = :br) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/cbraspag/core/converter.rb', line 8

def self.string_to_decimal(value, mode = :br)
  case mode
  when :br
    BigDecimal.new(value.to_s.gsub(".","").gsub(",","."))
  when :eua
    BigDecimal.new(value.to_s.gsub(",",""))
  end
end