Class: Timeprice::CLI::Presenters::Exchange
- Inherits:
-
Object
- Object
- Timeprice::CLI::Presenters::Exchange
- Includes:
- Formatting
- Defined in:
- lib/timeprice/cli/presenters/exchange.rb
Overview
Renders an ExchangeResult for the CLI in text and JSON formats.
Instance Method Summary collapse
-
#initialize(result) ⇒ Exchange
constructor
A new instance of Exchange.
- #json_hash ⇒ Object
- #text_lines ⇒ Object
Methods included from Formatting
#fmt_money, #fmt_rate, #round_money, #with_commas
Constructor Details
#initialize(result) ⇒ Exchange
Returns a new instance of Exchange.
12 13 14 |
# File 'lib/timeprice/cli/presenters/exchange.rb', line 12 def initialize(result) @result = result end |
Instance Method Details
#json_hash ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/timeprice/cli/presenters/exchange.rb', line 16 def json_hash @result.to_h.merge( amount: round_money(@result.amount, @result.to), original_amount: round_money(@result.original_amount, @result.from), rate: @result.rate.to_f.round(6) ) end |
#text_lines ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/timeprice/cli/presenters/exchange.rb', line 24 def text_lines [ "#{fmt_money(@result.amount, @result.to)} #{@result.to} on #{@result.date}", format(" %s %s -> %s %s", fmt_money(@result.original_amount, @result.from), @result.from, fmt_money(@result.amount, @result.to), @result.to), " #{rate_line}", ] end |