Class: Latinum::Formatters::PlainFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/latinum/formatters.rb

Overview

Formats a currency using a standard decimal notation.

Instance Method Summary collapse

Constructor Details

#initialize(name:) ⇒ PlainFormatter

Returns a new instance of PlainFormatter.



27
28
29
# File 'lib/latinum/formatters.rb', line 27

def initialize(name:)
	@name = name
end

Instance Method Details

#format(amount) ⇒ Object

Formats the amount using a general notation. e.g. “5.0 NZD”.



34
35
36
# File 'lib/latinum/formatters.rb', line 34

def format(amount)
	"#{amount.to_s('F')} #{@name}"
end

#from_integral(amount) ⇒ Object

Converts the amount to a decimal.



48
49
50
# File 'lib/latinum/formatters.rb', line 48

def from_integral(amount)
	amount.to_d
end

#to_integral(amount) ⇒ Object

Converts the amount directly to an integer, truncating any decimal part.



41
42
43
# File 'lib/latinum/formatters.rb', line 41

def to_integral(amount)
	amount.to_i
end