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.



12
13
14
# File 'lib/latinum/formatters.rb', line 12

def initialize(name:)
	@name = name
end

Instance Method Details

#format(amount) ⇒ Object

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



25
26
27
# File 'lib/latinum/formatters.rb', line 25

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

#from_integral(amount) ⇒ Object

Converts the amount to a decimal.



39
40
41
# File 'lib/latinum/formatters.rb', line 39

def from_integral(amount)
	amount.to_d
end

#parse(string) ⇒ Object

Parse a string into an amount.



18
19
20
# File 'lib/latinum/formatters.rb', line 18

def parse(string)
	BigDecimal(string)
end

#to_integral(amount) ⇒ Object

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



32
33
34
# File 'lib/latinum/formatters.rb', line 32

def to_integral(amount)
	amount.to_i
end