Module: TurkishNumeric::NumberPresenter

Included in:
TrNum
Defined in:
lib/turkish_numeric/number_presenter.rb

Overview

Responsible for providing helper methods to present numbers as text

Instance Method Summary collapse

Instance Method Details

#text_non_spaced(*parts) ⇒ String

Creates non-spaced string representation of the argument

Parameters:

  • parts (Array)

Returns:

  • (String)


27
28
29
# File 'lib/turkish_numeric/number_presenter.rb', line 27

def text_non_spaced(*parts)
  parts.join
end

#text_spaced(*parts) ⇒ String

Creates single spaced string representation of the argument

Parameters:

  • parts (Array)

Returns:

  • (String)


19
20
21
# File 'lib/turkish_numeric/number_presenter.rb', line 19

def text_spaced(*parts)
  parts.flatten.compact.join(' ')
end

#thousands_separated(numeric, sep: '.') ⇒ String

Create thousand seperated representaion of numeric value

Parameters:

  • numeric (Integer)
  • sep (String) (defaults to: '.')

Returns:

  • (String)


11
12
13
# File 'lib/turkish_numeric/number_presenter.rb', line 11

def thousands_separated(numeric, sep: '.')
  numeric.digits.each_slice(3).map(&:join).join(sep).reverse
end

#to_pennies(numeric) ⇒ Integer

Extracts pennies from the argument

Parameters:

  • numeric (Integer)

Returns:

  • (Integer)


35
36
37
38
39
# File 'lib/turkish_numeric/number_presenter.rb', line 35

def to_pennies(numeric)
  return numeric if numeric < 100

  numeric.to_s[0, 2].to_i
end