Module: Timeprice

Defined in:
lib/timeprice.rb,
lib/timeprice/cli.rb,
lib/timeprice/cli.rb,
lib/timeprice/point.rb,
lib/timeprice/errors.rb,
lib/timeprice/compare.rb,
lib/timeprice/sources.rb,
lib/timeprice/version.rb,
lib/timeprice/exchange.rb,
lib/timeprice/inflation.rb,
lib/timeprice/supported.rb,
lib/timeprice/data_loader.rb

Overview

Tiny shim so we can include currency context in the inflation line without bloating the value object — the result doesn’t carry currency, only country.

Defined Under Namespace

Modules: Compare, DataLoader, Exchange, Inflation, Sources, Supported Classes: CLI, CompareResult, DataNotFound, DateOutOfRange, Error, ExchangeResult, InflationResult, Point, UnsupportedCountry, UnsupportedCurrency, UnsupportedSchemaVersion

Constant Summary collapse

VERSION =
"0.2.0"
SUPPORTED_COUNTRIES =

Back-compat aliases — keep the old top-level constants pointing at the canonical lists so existing requires of “errors” keep working.

Supported::COUNTRIES
SUPPORTED_CURRENCIES =
Supported::CURRENCIES

Class Method Summary collapse

Class Method Details

.compare(amount:, from:, to:) ⇒ CompareResult

Compare an amount across two (currency, date) points: convert at the source date, then inflate in the destination currency. See README.md “Compare semantics” for why this order is correct.

Parameters:

  • amount (Numeric)
  • from (Point, Array(String, String))

    source point

  • to (Point, Array(String, String))

    destination point

Returns:



62
63
64
# File 'lib/timeprice.rb', line 62

def compare(amount:, from:, to:)
  Compare.run(amount: amount, from: from, to: to)
end

.exchange(amount:, from:, to:, date:) ⇒ ExchangeResult

Convert an amount between currencies on a specific date.

Parameters:

  • amount (Numeric)

    the original amount

  • from (String)

    source currency (ISO 4217)

  • to (String)

    destination currency (ISO 4217)

  • date (String)

    date as “YYYY-MM-DD”

Returns:

Raises:



50
51
52
# File 'lib/timeprice.rb', line 50

def exchange(amount:, from:, to:, date:)
  Exchange.convert(amount: amount, from: from, to: to, date: date)
end

.inflation(amount:, from:, to:, country:) ⇒ InflationResult

Inflation-adjust an amount between two dates using a country’s CPI.

Parameters:

  • amount (Numeric)

    the original amount

  • from (String)

    source date as “YYYY” or “YYYY-MM”

  • to (String)

    target date as “YYYY” or “YYYY-MM”

  • country (String)

Returns:

Raises:



37
38
39
# File 'lib/timeprice.rb', line 37

def inflation(amount:, from:, to:, country:)
  Inflation.adjust(amount: amount, from: from, to: to, country: country)
end