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.
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_hash ⇒ Object
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_lines ⇒ Object
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 |