Sha256: 0a2180afff7541a8790e4baa545ed59c2c002624e0564ae71b5bb438ab44ea7f

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

class String

  # Basado en soluciones de
  # http://stackoverflow.com/questions/6541209/decimals-and-commas-when-entering-a-number-into-a-ruby-on-rails-form 
  def a_decimal_nolocalizado
    delimiter = I18n::t('number.format.delimiter')
    separator = I18n::t('number.format.separator')
    self.gsub(/[#{delimiter}#{separator}]/, delimiter => '', separator => '.')
  end

  def a_decimal_localizado
    if !self || self == ''
      return ''
    end
    delimiter = I18n::t('number.format.delimiter')
    #puts "delimiter=#{delimiter}"
    separator = I18n::t('number.format.separator')
    #puts "separator=#{separator}"
    neg = self.split('-').first
    if neg == ''
      num = self.split('-')[1]
      neg = '-'
    else
      num = self
      neg = ''
    end
    #puts "neg=#{neg}"
    pent = num.split('.').first
    #puts "pent=#{pent}"
    pdec = num.split('.')[1]
    #puts "pdec=#{pdec}"
    pent = pent.reverse.gsub(/\d{3}/,"\\&#{delimiter}")
    #puts "pent=#{pent}"
    pent = pent.reverse.sub(/^[#{delimiter}]/, "") 
    #puts "pent=#{pent}"
    if pdec then
      return "#{neg}#{pent}#{separator}#{pdec}"
    else
      return "#{neg}#{pent}"
    end
  end

  # Convierte una cadena a altas y bajas es decir primera letra de
  # cada palabra mayúscula y las demás de la palabra en minúsculas.
  def altas_bajas
    inip = true
    r = ''
    self.each_char do |c|
      if inip
        r << c.upcase
      else
        r << c.downcase
      end
      inip = !c.match(/^[[:alpha:]]$/)
    end
    return r
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
msip-2.2.0.alfa3 lib/ext/string.rb
msip-2.2.0.alfa2 lib/ext/string.rb
msip-2.2a2 lib/ext/string.rb