class Latinum::Formatters::PlainFormatter
Formats a currency using a standard decimal notation.
Public Class Methods
new(name:)
click to toggle source
# File lib/latinum/formatters.rb, line 12 def initialize(name:) @name = name end
Public Instance Methods
format(amount)
click to toggle source
Formats the amount using a general notation. e.g. “5.0 NZD”. @returns [String] The formatted string.
# File lib/latinum/formatters.rb, line 25 def format(amount) "#{amount.to_s('F')} #{@name}" end
from_integral(amount)
click to toggle source
Converts the amount to a decimal. @parameter amount [Integer] The amount to convert to a decimal. @returns [BigDecimal] The converted amount.
# File lib/latinum/formatters.rb, line 39 def from_integral(amount) amount.to_d end
parse(string)
click to toggle source
Parse a string into an amount. @returns [BigDecimal] The parsed amount.
# File lib/latinum/formatters.rb, line 18 def parse(string) BigDecimal(string) end
to_integral(amount)
click to toggle source
Converts the amount directly to an integer, truncating any decimal part. @parameter amount [BigDecimal] The amount to convert to an integral. @returns [Integer] The converted whole number integer.
# File lib/latinum/formatters.rb, line 32 def to_integral(amount) amount.to_i end