Class: Timeprice::CLI::Presenters::Inflation
- Inherits:
-
Object
- Object
- Timeprice::CLI::Presenters::Inflation
- 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
-
#initialize(result) ⇒ Inflation
constructor
A new instance of Inflation.
- #json_hash ⇒ Object
- #text_lines ⇒ Object
Methods included from Formatting
#fmt_money, #fmt_rate, #round_money, #with_commas
Constructor Details
#initialize(result) ⇒ Inflation
Returns a new instance of Inflation.
12 13 14 15 |
# File 'lib/timeprice/cli/presenters/inflation.rb', line 12 def initialize(result) @result = result @ccy = result.country_currency_label end |
Instance Method Details
#json_hash ⇒ Object
17 18 19 20 21 22 |
# File 'lib/timeprice/cli/presenters/inflation.rb', line 17 def json_hash @result.to_h.merge( amount: round_money(@result.amount, @ccy), original_amount: round_money(@result.original_amount, @ccy) ) end |
#text_lines ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/timeprice/cli/presenters/inflation.rb', line 24 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} ยท #{@result.granularity} CPI", ] end |