timeprice 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +82 -0
  3. data/DATA_LICENSES.md +2 -1
  4. data/README.md +15 -6
  5. data/data/cpi/eu.json +23 -1
  6. data/data/cpi/jp.json +18 -2
  7. data/data/cpi/uk.json +23 -1
  8. data/data/cpi/us.json +29 -1
  9. data/data/cpi/vn.json +362 -34
  10. data/data/fx/usd/1983.json +7 -8
  11. data/data/fx/usd/1986.json +7 -8
  12. data/data/fx/usd/1987.json +7 -8
  13. data/data/fx/usd/1988.json +7 -8
  14. data/data/fx/usd/1989.json +7 -8
  15. data/data/fx/usd/1990.json +7 -8
  16. data/data/fx/usd/1991.json +7 -8
  17. data/data/fx/usd/1992.json +7 -8
  18. data/data/fx/usd/1993.json +7 -8
  19. data/data/fx/usd/1994.json +7 -8
  20. data/data/fx/usd/1995.json +7 -8
  21. data/data/fx/usd/1996.json +7 -8
  22. data/data/fx/usd/1997.json +7 -8
  23. data/data/fx/usd/1998.json +7 -8
  24. data/data/fx/usd/1999.json +266 -525
  25. data/data/fx/usd/2000.json +262 -517
  26. data/data/fx/usd/2001.json +261 -512
  27. data/data/fx/usd/2002.json +262 -514
  28. data/data/fx/usd/2003.json +262 -514
  29. data/data/fx/usd/2004.json +266 -522
  30. data/data/fx/usd/2005.json +264 -521
  31. data/data/fx/usd/2006.json +262 -514
  32. data/data/fx/usd/2007.json +262 -514
  33. data/data/fx/usd/2008.json +263 -516
  34. data/data/fx/usd/2009.json +263 -516
  35. data/data/fx/usd/2010.json +265 -523
  36. data/data/fx/usd/2011.json +264 -521
  37. data/data/fx/usd/2012.json +263 -516
  38. data/data/fx/usd/2013.json +262 -514
  39. data/data/fx/usd/2014.json +262 -514
  40. data/data/fx/usd/2015.json +263 -516
  41. data/data/fx/usd/2016.json +264 -521
  42. data/data/fx/usd/2017.json +262 -514
  43. data/data/fx/usd/2018.json +262 -514
  44. data/data/fx/usd/2019.json +262 -514
  45. data/data/fx/usd/2020.json +264 -518
  46. data/data/fx/usd/2021.json +265 -523
  47. data/data/fx/usd/2022.json +264 -521
  48. data/data/fx/usd/2023.json +262 -514
  49. data/data/fx/usd/2024.json +263 -516
  50. data/data/fx/usd/2025.json +5 -5
  51. data/data/fx/usd/2026.json +5 -5
  52. data/lib/timeprice/cli/formatting.rb +34 -0
  53. data/lib/timeprice/cli/presenters/compare.rb +46 -0
  54. data/lib/timeprice/cli/presenters/exchange.rb +45 -0
  55. data/lib/timeprice/cli/presenters/inflation.rb +37 -0
  56. data/lib/timeprice/cli/presenters/sources.rb +65 -0
  57. data/lib/timeprice/cli.rb +83 -114
  58. data/lib/timeprice/compare.rb +17 -34
  59. data/lib/timeprice/cpi_lookup.rb +64 -0
  60. data/lib/timeprice/data_loader.rb +13 -6
  61. data/lib/timeprice/exchange.rb +35 -17
  62. data/lib/timeprice/granularity.rb +46 -0
  63. data/lib/timeprice/inflation.rb +20 -71
  64. data/lib/timeprice/point.rb +30 -11
  65. data/lib/timeprice/sources/coverage.rb +71 -0
  66. data/lib/timeprice/sources.rb +7 -54
  67. data/lib/timeprice/supported.rb +12 -5
  68. data/lib/timeprice/version.rb +1 -1
  69. metadata +9 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 160a9501bc1004df45cd71202f3ae07711068adade2118cfe4605a2e92d92f6f
4
- data.tar.gz: 68ea05103245f2bb1fb02d701fd5db6e1bb814a2b47d20f6eb9011d94a57b269
3
+ metadata.gz: a91644504f73e6324d522d189233539a5515ca51cf0be58b1a34da90ff78220d
4
+ data.tar.gz: f6120dc38bb433e1dc8ac56e523b3c547d9323b578f34a27bddee3e43b48c9a2
5
5
  SHA512:
6
- metadata.gz: fdddfd9cbcf4cefad6ee73134eb8ef3e5ad5b863aa8d5a78fa789b8890cefec0690cf3c1022f1b596c2bdeaf6f9a8f1122d8ff6ef9adfb7dd393e0aa9346afb6
7
- data.tar.gz: 4342d02e30f4058f6e7a98eedab2fd0fa54b14031f061bf4d17b093d02f6a1e5cd16ea1f994e7d868cc893fe29119bdae1a398724665f14502c9b135ee1396b0
6
+ metadata.gz: b8b0f99a9962bad944a02499761a586e860d50a3707e70de4d1549c6bf624ea5bf1a9d1d2beae488abdfc6646d825320259a196bfac177e64c25edab90e721e5
7
+ data.tar.gz: 54bb2545e7c9f9bbdb202994f3d5f53bb020a36bde0a2d8627c734a1c0e4312fcbe0237ce2b23409af9253ddc809ae74129dec43b17b94c559bcefa8917142cf
data/CHANGELOG.md CHANGED
@@ -5,6 +5,88 @@ Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.4.0] - 2026-05-11
9
+
10
+ ### Changed
11
+ - **Schema v1 → v2.** Two structural data-layer changes, bundled under a
12
+ single bump:
13
+ - FX year files gain an optional top-level `annual` block. World Bank's
14
+ annual VND/USD average is stored there exactly once per year instead of
15
+ being broadcast across every daily date key. `Exchange.lookup_usd_base`
16
+ falls back from daily to annual when no daily entry exists within ±7
17
+ days and tags the result with `Granularity::ANNUAL`. `Compare` merges
18
+ FX granularity with CPI granularity (worst-precision wins).
19
+ - CPI provenance moves from a per-period map (`{"2025-01": "bls", ...}`)
20
+ to a compact range list (`[{series, from, to, provider}, ...]`). Single
21
+ -provider files (US/UK/EU/JP) collapse to 1–2 ranges; VN keeps the
22
+ WB→IMF transition explicit. ~42 kb saved across the 5 CPI files; one
23
+ real US data gap at 2025-10 is now visible instead of buried.
24
+ - `country_file.rb` rebase label now preserves the original base reference
25
+ alongside the rebase date (e.g. `"2010=100 (rebased 2026-05-11)"`).
26
+
27
+ ### Added
28
+ - Multi-source CPI chain for Vietnam: IMF Data Portal CPI dataflow
29
+ (`api.imf.org`, SDMX 2.1) is the monthly primary; World Bank `FP.CPI.TOTL`
30
+ remains as the annual fallback. The on-disk `data/cpi/vn.json` gains two
31
+ additive fields — `provenance` (per-period source id) and `providers`
32
+ (per-source status array) — so consumers can see which upstream supplied
33
+ each datapoint. Schema version is unchanged; old readers ignore the new
34
+ fields. Other country files (US, UK, EU, JP) gain the same fields on the
35
+ next refresh.
36
+ - Internal: `Sources::Provider` / `Sources::CountryFile` / `Sources::MergePolicy`
37
+ seam for layering multiple providers into a single country file with
38
+ per-period provenance. Designed so future fresher sources (e.g. JP via
39
+ e-Stat) can be added as one more entry without further plumbing.
40
+
41
+ ## [0.3.0] - 2026-05-11
42
+
43
+ ### Added
44
+ - `Timeprice::CpiLookup` and `Timeprice::CpiPoint` (Data.define of value +
45
+ granularity). Owns all knowledge of the parsed CPI JSON shape so
46
+ `Inflation.adjust` is a 6-line orchestration.
47
+ - `Timeprice::Sources::Coverage` — isolates runtime filesystem walking
48
+ (FX year scan, JSON.parse of rate files) from the attribution registry.
49
+ - `Timeprice::Point#fx_anchor_date` — resolves a year / month / day `Point`
50
+ to the day-resolved string FX lookup needs (mid-year for `YYYY`,
51
+ mid-month for `YYYY-MM`).
52
+ - `Timeprice::Supported.decimals_for(currency)` — single source of truth
53
+ for ISO 4217 minor-unit counts; non-CLI callers of `Timeprice.exchange`
54
+ can now format results consistently.
55
+ - `Timeprice::CLI::Presenters::{Inflation, Exchange, Compare, Sources}` —
56
+ each presenter exposes `#text_lines` and `#json_hash`; the CLI dispatches
57
+ via a single `#render(presenter)` helper.
58
+
59
+ ### Changed
60
+ - CLI output redesigned for readability: every `inflation`, `fx`, and `compare`
61
+ command now leads with the answer on line 1 (e.g. `3,530,921 VND in 2024`),
62
+ followed by the calculation chain indented below. `head -1` extracts just
63
+ the headline. Numbers are comma-grouped; JSON output is rounded to currency
64
+ precision (no more `1861291.9999999998`).
65
+ - `timeprice sources` now renders as an aligned `ID / SOURCE / LICENSE /
66
+ COVERAGE` table by default. Use `timeprice sources --verbose` (`-v`) for the
67
+ previous detailed view with license URLs and full attribution.
68
+ - Top-level `timeprice help` rewritten — no more truncated descriptions; lists
69
+ command names + descriptions, matching the `git` / `gh` / `cargo` convention.
70
+ - `Point.coerce` rewritten with pattern matching; the CLI's
71
+ `parse_compare_token` now delegates to it instead of re-implementing
72
+ the shape rules.
73
+ - `Compare.resolve_points` uses explicit `raise … unless` guards instead of
74
+ `… || (raise …)` nil-pun.
75
+
76
+ ### Removed
77
+ - Undocumented back-compat constants: `Timeprice::SUPPORTED_COUNTRIES`,
78
+ `Timeprice::SUPPORTED_CURRENCIES`, and `Timeprice::Compare::CURRENCY_TO_COUNTRY`.
79
+ Use `Supported::COUNTRIES`, `Supported::CURRENCIES`, and
80
+ `Supported::CURRENCY_TO_COUNTRY` directly.
81
+ - `Lint/DuplicateBranch` RuboCop exclusion for `cli.rb` — the duplicate
82
+ was collapsed into a single `rescue Timeprice::Error, ArgumentError`.
83
+
84
+ ### Fixed
85
+ - Friendlier error messages: `Error: AMOUNT must be a number, got "abc"`
86
+ instead of Ruby's raw `invalid value for Float(): "abc"`. Missing-options
87
+ errors now say `missing required options: --from, --to` with a `See:
88
+ timeprice help inflation` hint.
89
+
8
90
  ## [0.2.0] - 2026-05-11
9
91
 
10
92
  ### Added
data/DATA_LICENSES.md CHANGED
@@ -12,7 +12,8 @@ string.
12
12
  | UK Office for National Statistics | `D7BT` (UK CPI all-items) | Open Government Licence v3.0 | https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/ | Contains public sector information licensed under the Open Government Licence v3.0 |
13
13
  | Eurostat | `prc_hicp_midx` (Euro area HICP) | Eurostat reuse policy — free reuse with source attribution | https://ec.europa.eu/eurostat/about-us/policies/copyright | Source: Eurostat |
14
14
  | World Bank | `FP.CPI.TOTL` (JP CPI fallback) | Creative Commons Attribution 4.0 International (CC BY 4.0) | https://datacatalog.worldbank.org/public-licenses#cc-by | Source: World Bank, FP.CPI.TOTL |
15
- | World Bank | `FP.CPI.TOTL` (VN CPI) | Creative Commons Attribution 4.0 International (CC BY 4.0) | https://datacatalog.worldbank.org/public-licenses#cc-by | Source: World Bank, FP.CPI.TOTL |
15
+ | World Bank | `FP.CPI.TOTL` (VN CPI, annual fallback) | Creative Commons Attribution 4.0 International (CC BY 4.0) | https://datacatalog.worldbank.org/public-licenses#cc-by | Source: World Bank, FP.CPI.TOTL |
16
+ | International Monetary Fund | CPI dataflow `VNM.CPI._T.IX.M` via IMF Data Portal (VN CPI, monthly primary) | Free reuse with attribution per IMF terms | https://www.imf.org/external/terms.htm | Source: IMF Data Portal CPI dataflow |
16
17
  | European Central Bank (via Frankfurter) | Daily reference rates, USD base, EUR/GBP/JPY | ECB reference rates — free reuse; Frankfurter is a non-commercial republisher with no separate license | https://www.ecb.europa.eu/services/disclaimer/html/index.en.html | FX data: European Central Bank reference rates via Frankfurter |
17
18
  | World Bank | `PA.NUS.FCRF` (VND annual average FX, broadcast daily) | Creative Commons Attribution 4.0 International (CC BY 4.0) | https://datacatalog.worldbank.org/public-licenses#cc-by | VND FX: World Bank, PA.NUS.FCRF |
18
19
 
data/README.md CHANGED
@@ -32,16 +32,25 @@ Requires Ruby >= 3.2.
32
32
 
33
33
  ```bash
34
34
  $ timeprice inflation 100 --from 1990-01 --to 2024-01 --country US
35
- 100.00 USD in 1990-01 is 242.09 USD in 2024-01 (US, granularity: monthly)
35
+ 242.09 USD in 2024-01
36
+ 100.00 USD (1990-01) -> 242.09 USD (2024-01)
37
+ US · monthly CPI
36
38
 
37
39
  $ timeprice fx 100 USD JPY --date 2010-06-15
38
- 100.00 USD on 2010-06-15 = 9118.00 JPY (rate: 91.1800)
40
+ 9,118 JPY on 2010-06-15
41
+ 100.00 USD -> 9,118 JPY
42
+ rate 91.18
39
43
 
40
44
  $ timeprice compare 100 --from "2010 USD" --to "2024 VND"
41
- 100.00 USD in 2010 -> 3530920.58 VND in 2024
42
- steps: convert at 2010 (fx rate 18612.920000) -> 1861292.0000 VND, then inflate in VN (cpi ratio 1.897027, granularity: annual)
45
+ 3,530,921 VND in 2024
46
+ 100.00 USD (2010)
47
+ -> fx @ 18,612.92 -> 1,861,292 VND (2010)
48
+ -> inflate x1.8970 VN -> 3,530,921 VND (2024, annual)
43
49
  ```
44
50
 
51
+ The first line of each result is the answer — pipe through `head -1` if a
52
+ script only needs the headline figure.
53
+
45
54
  Every command supports `--json` for machine-readable output:
46
55
 
47
56
  ```bash
@@ -89,7 +98,7 @@ Coverage is derived from the bundled `data/` files. Re-check with `timeprice sou
89
98
  | United Kingdom | GBP | ONS CPI all-items (`D7BT`) | Monthly + annual | 1988-01 → present |
90
99
  | Eurozone (EA) | EUR | Eurostat HICP (`prc_hicp_midx`) | Monthly + annual | 1996-01 → present |
91
100
  | Japan | JPY | World Bank `FP.CPI.TOTL` (fallback) | Annual | 1960 → 2024 |
92
- | Vietnam | VND | World Bank `FP.CPI.TOTL` | Annual | 1995 → 2024 |
101
+ | Vietnam | VND | IMF Data Portal CPI dataflow (monthly primary) + World Bank `FP.CPI.TOTL` (annual fallback) | Monthly + annual | 1995 → present |
93
102
 
94
103
  **FX (USD base):** ECB reference rates via Frankfurter for **EUR / GBP / JPY**, daily
95
104
  1999 → present. **VND** uses the World Bank annual average (`PA.NUS.FCRF`) broadcast to
@@ -249,7 +258,7 @@ license — see `DATA_LICENSES.md` and `NOTICE` for the full table and license U
249
258
  - **UK CPI:** Contains public sector information licensed under the Open Government Licence v3.0.
250
259
  - **Eurozone HICP:** Source: Eurostat (reuse permitted with attribution).
251
260
  - **Japan CPI (fallback):** Source: World Bank, FP.CPI.TOTL (CC BY 4.0).
252
- - **Vietnam CPI:** Source: World Bank, FP.CPI.TOTL (CC BY 4.0).
261
+ - **Vietnam CPI:** Sources: IMF Data Portal CPI dataflow (monthly primary); World Bank, FP.CPI.TOTL (annual fallback, CC BY 4.0).
253
262
  - **FX rates:** European Central Bank reference rates via Frankfurter.
254
263
  - **VND FX (annual broadcast):** World Bank, PA.NUS.FCRF (CC BY 4.0).
255
264
 
data/data/cpi/eu.json CHANGED
@@ -395,7 +395,29 @@
395
395
  "2025-11": 129.33,
396
396
  "2025-12": 129.56
397
397
  },
398
- "schema_version": 1,
398
+ "provenance": [
399
+ {
400
+ "series": "monthly",
401
+ "from": "1996-01",
402
+ "to": "2025-12",
403
+ "provider": "eurostat"
404
+ },
405
+ {
406
+ "series": "annual",
407
+ "from": "1996",
408
+ "to": "2025",
409
+ "provider": "eurostat"
410
+ }
411
+ ],
412
+ "providers": [
413
+ {
414
+ "fetched_at": "2026-05-11",
415
+ "id": "eurostat",
416
+ "label": "Eurostat prc_hicp_midx (HICP, EA all current members, CP00, 2015=100)",
417
+ "status": "ok"
418
+ }
419
+ ],
420
+ "schema_version": 2,
399
421
  "source": "Eurostat prc_hicp_midx (HICP, EA all current members, CP00, 2015=100)",
400
422
  "updated_at": "2026-05-11"
401
423
  }
data/data/cpi/jp.json CHANGED
@@ -69,7 +69,23 @@
69
69
  "base_year": "2010=100",
70
70
  "country": "JP",
71
71
  "monthly": {},
72
- "schema_version": 1,
73
- "source": "World Bank FP.CPI.TOTL (annual)",
72
+ "provenance": [
73
+ {
74
+ "series": "annual",
75
+ "from": "1960",
76
+ "to": "2024",
77
+ "provider": "world_bank"
78
+ }
79
+ ],
80
+ "providers": [
81
+ {
82
+ "fetched_at": "2026-05-11",
83
+ "id": "world_bank",
84
+ "label": "World Bank FP.CPI.TOTL (annual, JP fallback)",
85
+ "status": "ok"
86
+ }
87
+ ],
88
+ "schema_version": 2,
89
+ "source": "World Bank FP.CPI.TOTL (annual, JP fallback)",
74
90
  "updated_at": "2026-05-11"
75
91
  }
data/data/cpi/uk.json CHANGED
@@ -502,7 +502,29 @@
502
502
  "2026-02": 140.1,
503
503
  "2026-03": 141.0
504
504
  },
505
- "schema_version": 1,
505
+ "provenance": [
506
+ {
507
+ "series": "monthly",
508
+ "from": "1988-01",
509
+ "to": "2026-03",
510
+ "provider": "ons"
511
+ },
512
+ {
513
+ "series": "annual",
514
+ "from": "1988",
515
+ "to": "2025",
516
+ "provider": "ons"
517
+ }
518
+ ],
519
+ "providers": [
520
+ {
521
+ "fetched_at": "2026-05-11",
522
+ "id": "ons",
523
+ "label": "ONS D7BT — UK CPI all-items index (2015=100)",
524
+ "status": "ok"
525
+ }
526
+ ],
527
+ "schema_version": 2,
506
528
  "source": "ONS D7BT — UK CPI all-items index (2015=100)",
507
529
  "updated_at": "2026-05-11"
508
530
  }
data/data/cpi/us.json CHANGED
@@ -474,7 +474,35 @@
474
474
  "2026-02": 326.785,
475
475
  "2026-03": 330.213
476
476
  },
477
- "schema_version": 1,
477
+ "provenance": [
478
+ {
479
+ "series": "monthly",
480
+ "from": "1990-01",
481
+ "to": "2025-09",
482
+ "provider": "bls"
483
+ },
484
+ {
485
+ "series": "monthly",
486
+ "from": "2025-11",
487
+ "to": "2026-03",
488
+ "provider": "bls"
489
+ },
490
+ {
491
+ "series": "annual",
492
+ "from": "1990",
493
+ "to": "2024",
494
+ "provider": "bls"
495
+ }
496
+ ],
497
+ "providers": [
498
+ {
499
+ "fetched_at": "2026-05-11",
500
+ "id": "bls",
501
+ "label": "BLS CUUR0000SA0 (CPI-U, U.S. city average, all items)",
502
+ "status": "ok"
503
+ }
504
+ ],
505
+ "schema_version": 2,
478
506
  "source": "BLS CUUR0000SA0 (CPI-U, U.S. city average, all items)",
479
507
  "updated_at": "2026-05-11"
480
508
  }