Sha256: 971b6e1cec31c43d76c3aec58335de5d2dca07c65ee9c1e0874b985ce832be98
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
module CheckWriter # Provides formatting methods for Check attributes module AttributeFormatting # Returns an integer representing the number of cents of the amount # # amount = 3.23 => 23 def cents ((amount.to_f - dollars) * 100).to_i end # Returns an integer representing the number of dollars of the amount # # amount = 3.23 => 3 def dollars amount.to_i end # Formats the amount as currency # # amount = 1000 => $1,000.00 def formatted_amount separated_dollars = dollars.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,") "$#{separated_dollars}.#{cents}" end # Converts numeric amount of the check into words. # # amount = 1.12 => One Dollar and Twelve Cents def amount_in_words # Wrap cents in string before calling numwords to avoid # SafeBuffer cannot modify string in place error cents = "#{self.cents}".en.numwords "#{dollars.en.numwords} Dollars and #{cents} Cents".titleize end # Formats date def formatted_date date.strftime('%B %e, %Y') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
check_writer-0.1.0 | lib/check_writer/attribute_formatting.rb |