Sha256: d73095fd91bbc45e525d7dadd4beb9c19a4aa3a7826326d66351e38562d0e85e

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module Buckaroo
  module Ideal
    module Util
      extend self
      
      if RUBY_VERSION < "1.9"
        
        require 'iconv'
        
        STRIP_ACCENTS_RE = /[\^~"`']/
        
        def to_normalized_string(string)
          Iconv.iconv('US-ASCII//IGNORE//TRANSLIT', 'UTF-8', string).to_s.gsub(STRIP_ACCENTS_RE, '')
        end
        
      else
        
        require 'transliterator'
        
        def to_normalized_string(string)
          Transliterator.asciify(string.to_s)
        end
        
      end
      
      def to_cents(amount)
        (amount.to_f * 100).round
      end
      
      def from_cents(cents)
        cents.to_f / 100
      end
      
      def to_numeric_boolean(boolean)
        boolean ? 1 : 0
      end
      
      def from_numeric_boolean(number)
        number.to_i == 1
      end
      
      def compact(subject)
        subject = subject.dup
        
        if subject.is_a?(Hash)
          subject.each do |key, value|
            subject.delete(key) unless value
          end
        end
        
        subject
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
buckaroo-ideal-0.0.2 lib/buckaroo-ideal/util.rb