Class: Timeprice::CLI::Presenters::Inflation

Inherits:
Object
  • Object
show all
Includes:
Formatting
Defined in:
lib/timeprice/cli/presenters/inflation.rb

Overview

Renders an InflationResult for the CLI in text and JSON formats.

Instance Method Summary collapse

Methods included from Formatting

#fmt_money, #fmt_rate, #round_money, #with_commas

Constructor Details

#initialize(result) ⇒ Inflation

Returns a new instance of Inflation.



13
14
15
16
# File 'lib/timeprice/cli/presenters/inflation.rb', line 13

def initialize(result)
  @result = result
  @ccy = result.country_currency_label
end

Instance Method Details

#json_hashObject



18
19
20
21
22
23
# File 'lib/timeprice/cli/presenters/inflation.rb', line 18

def json_hash
  @result.to_h.merge(
    amount: round_money(@result.amount, @ccy),
    original_amount: round_money(@result.original_amount, @ccy)
  )
end

#text_linesObject



25
26
27
28
29
30
31
32
33
# File 'lib/timeprice/cli/presenters/inflation.rb', line 25

def text_lines
  [
    "#{fmt_money(@result.amount, @ccy)} #{@ccy}  in #{@result.to}",
    format("  %s %s (%s) -> %s %s (%s)",
           fmt_money(@result.original_amount, @ccy), @ccy, @result.from,
           fmt_money(@result.amount, @ccy), @ccy, @result.to),
    "  #{@result.country} ยท #{Granularity.humanize(@result.granularity)} CPI",
  ]
end