module Jamef::Helper

Constants

ACCENTS_MAPPING

Public Class Methods

format_boolean(value) click to toggle source
# File lib/jamef/helper.rb, line 72
def self.format_boolean value
  value ? 'S' : 'N'
end
format_city(value) click to toggle source
# File lib/jamef/helper.rb, line 51
def self.format_city value
  unaccent(value).upcase
end
format_date(value) click to toggle source
# File lib/jamef/helper.rb, line 64
def self.format_date value
  value.strftime("%d/%m/%Y")
end
format_decimal(value) click to toggle source
# File lib/jamef/helper.rb, line 43
def self.format_decimal value
  sprintf('%.2f', Float(value))
end
format_document(value) click to toggle source
# File lib/jamef/helper.rb, line 59
def self.format_document value
  only_numbers(value)
end
format_state(value) click to toggle source
# File lib/jamef/helper.rb, line 55
def self.format_state value
  value.upcase
end
format_time(value) click to toggle source
# File lib/jamef/helper.rb, line 68
def self.format_time value
  value.strftime("%H:%M")
end
format_zip(value) click to toggle source
# File lib/jamef/helper.rb, line 47
def self.format_zip value
  only_numbers(value)
end
only_numbers(string) click to toggle source
# File lib/jamef/helper.rb, line 39
def self.only_numbers string
  string.gsub(/\D*/,'')
end
parse_date(value) click to toggle source
# File lib/jamef/helper.rb, line 76
def self.parse_date value
  Date.strptime(value, '%d/%m/%y')
end
parse_decimal(value) click to toggle source
# File lib/jamef/helper.rb, line 80
def self.parse_decimal value
  Float(value)
end
unaccent(string) click to toggle source

Remove the accents from the string. Uses String::ACCENTS_MAPPING as the source map.

# File lib/jamef/helper.rb, line 29
def self.unaccent string
  str = string.dup
    ACCENTS_MAPPING.each {|letter,accents|
    packed = accents.pack('U*')
    rxp = Regexp.new("[#{packed}]", nil)
    str.gsub!(rxp, letter)
  }
  str
end