Module: StarlingTerminal::Utils
- Defined in:
- lib/starling_terminal/utils.rb
Overview
Utility functions for building, formatting and styling the statement
Constant Summary collapse
- CURRENCY_SYMBOLS =
A map from currency code (e.g. “GBP”, “EUR”) to symbol for display in the table
{ 'GBP' => '£', 'USD' => '$', 'EUR' => '€' }.freeze
Class Method Summary collapse
-
.colour_for_amount(amount) ⇒ :red, :green
Returns the colour an amount should be displayed in (red for negative amounts, green for positive).
-
.float_to_currency(float, currency:) ⇒ String
Converts a Float to a currency valuable with symbol or code, suitable for display.
-
.present_time(time) ⇒ String
Presents a Time as a string in the standard UK format.
Class Method Details
.colour_for_amount(amount) ⇒ :red, :green
Returns the colour an amount should be displayed in (red for negative amounts, green for positive)
40 41 42 |
# File 'lib/starling_terminal/utils.rb', line 40 def self.colour_for_amount(amount) amount > 0 ? :green : :red end |
.float_to_currency(float, currency:) ⇒ String
Converts a Float to a currency valuable with symbol or code, suitable for display
19 20 21 22 23 24 |
# File 'lib/starling_terminal/utils.rb', line 19 def self.float_to_currency(float, currency:) currency_symbol = CURRENCY_SYMBOLS.fetch(currency, nil) return format("#{currency_symbol}%.2f", float) if currency_symbol format("%.2f #{currency}", float) end |
.present_time(time) ⇒ String
Presents a Time as a string in the standard UK format
31 32 33 |
# File 'lib/starling_terminal/utils.rb', line 31 def self.present_time(time) time.strftime('%-d/%-m/%Y %H:%M') end |