io.randomseed.bankster.util.importer
added in 1.0.0
Bankster library, import-export operations.
countries-load
added in 1.0.0
(countries-load & [pathname])Reads CSV file in a format compliant with Joda Money and returns a map with currency to countries associations where countries are sets. The pathname should be relative to the resources directory.
currencies-load
added in 1.0.0
(currencies-load & [pathname])Reads a CSV file compliant with Joda Money and returns a sequence of currencies.
The pathname should be relative to the resources directory.
currency->map
added in 1.0.0
(currency->map {:keys [:numeric :scale :kind], :as c})Takes a currency and returns a map suitable for putting into a configuration file. Extension fields are ignored.
default-export-currency-oriented-filename
added in 2.0.0
Default EDN export file (currency-oriented).
default-resource-must-exist-file
added in 1.0.0
Filename in a default resource container that must exist.
dump
added in 1.0.0
(dump & args)For the given filename (defaults to default-dump-filename) and a registry (defaults to a global registry) creates a dump in EDN format.
Filename will be placed in the default directory of resources (the same directory as config.edn).
export
added in 1.0.0
(export & args)For the given filename (defaults to default-export-filename) and a registry (defaults to a global registry) creates a configuration file in EDN format.
Filename will be placed in the default directory of resources (the same directory that holds config.edn).
export-currency-oriented
added in 2.0.0
(export-currency-oriented & args)For the given filename (defaults to default-export-currency-oriented-filename) and a registry (defaults to a global registry) creates a currency-oriented configuration file in EDN format.
Currency-oriented export embeds per-currency properties (countries, localized properties and traits) into the maps under :currencies. Top-level branches keep only orphaned entries.
handler-gen
(handler-gen names)Generates handler functions for tagged literals for each namespaced currency. Each function will have a prefixed name.
import-seed
added in 2.0.0
Filename in a default resource container which is a static seed for data when importing.
joda->bankster-dump
added in 1.0.0
(joda->bankster-dump)Reads Joda Money CSV files and creates a registry dump named resources/io/randomseed/bankster/registry-dump.edn.
joda->bankster-export
added in 1.0.0
(joda->bankster-export)Reads Joda Money CSV files and creates a configuration file named resources/io/randomseed/bankster/registry-export.edn.
joda-import
added in 1.0.0
(joda-import)(joda-import countries-pathname currencies-pathname)Reads CSV files with countries and currencies definitions (Joda Money format) and returns a registry.
localized->map
added in 1.0.0
(localized->map m)Takes a localized map entry (1st level) and returns a map suitable for putting into a configuration file.
map->currency-oriented
added in 2.0.0
(map->currency-oriented m)Takes a configuration map in a branch-oriented shape (as produced by registry->map) and returns a currency-oriented variant.
Per-currency properties are embedded into each currency map under :currencies: - :countries (vector of country IDs), - :localized (localized properties map), - :traits (vector of traits), - :weight (currency weight).
Top-level branches :countries, :localized, :traits and :weights are reduced to contain only orphaned entries (i.e. those not associated with any known currency IDs).
merge-registry
added in 2.0.0
(merge-registry dst src)(merge-registry dst src verbose?)(merge-registry dst src verbose? preserve-fields)(merge-registry dst src verbose? preserve-fields iso-like?)Merges two registries by registering currencies from src into dst.
Hierarchies (stored in :hierarchies) and extension data (stored in :ext) are merged as well.
When verbose? is truthy it prints a message for each currency which is present in src but not in dst.
When preserve-fields is given (a sequence of currency record keys, e.g. [:domain :kind]) and a currency is being replaced in dst, the values of these fields are preserved from the original currency in dst.
Special sentinel keywords may be included in preserve-fields:
::localizedpreserve localized properties fromdst,::countriespreserve assigned countries fromdst.
When iso-like? is truthy and the source currency is ISO-like (domain :ISO-4217 or :ISO-4217-LEGACY) then the currency identity is treated as its ISO code (name part of the ID). If the source currency is a legacy ISO currency then its destination ID is normalized to :iso-4217-legacy/CODE and it replaces a previously existing :CODE entry (including migration of attached country mappings and localized properties).
Note: in ISO-like mode :domain is never preserved from dst for ISO-like currencies (even if present in preserve-fields), to allow aligning ISO vs legacy ISO classification based on the source.
Legacy currency weight: when a legacy currency has weight 0 and the weight was not explicitly set (presence in :cur-id->weight) in either source or destination, it is set to default-legacy-weight. Explicit weight 0 is preserved.
readers-export
added in 1.0.0
(readers-export)(readers-export registry)(readers-export registry filenames)(readers-export registry filenames data-filename)(readers-export registry filenames data-filename handlers-pathname handlers-namespace)Creates clojure source code files with reader functions for tagged literals handling on a basis of registry information and data reader map files referring to the created handlers.
The purpose of generation is primarily to create handlers for literals in forms of #money/NS…, where NS is a namespace that corresponds to a namespace of a currency. Possible namespaces are taken from a registry (a map from its field .cur-id->cur).
The function takes a registry (defaults to a global registry if not given), a sequence of reader filenames (defaults to default-reader-filenames), default handlers pathname (defaults to default-handlers-pathname) and default handlers namespace (defaults to default-handlers-namespace).
Default namespace is a namespace in which money handlers will be defined. These handlers will be written to a file which pathname is constructed using the following tactic:
-
Obtain the directory of the first filename from the given filenames list using Java’s resource lookup. The assumption is it should be src directory of a project.
-
Append the file path passed as the handlers-pathname.
As for data reader map files, their directory name is also based on the lookup of the first filename. Each filename will be populated with the same content which is a map associating tagged literal with a function.
registry->map
added in 1.0.0
(registry->map)(registry->map registry)Takes a registry and returns a map suitable for putting into a configuration file. Extension fields are ignored. When registry is not given it uses the global one.
registry->map-currency-oriented
added in 2.0.0
(registry->map-currency-oriented)(registry->map-currency-oriented registry)Like registry->map, but produces a currency-oriented configuration map by embedding per-currency properties (countries, localized properties, traits) into the currency maps. Orphaned top-level entries are kept.
seed-import
added in 2.0.0
(seed-import)(seed-import resource-path)Loads seed data from an EDN resource file (defaults to seed.edn) and returns a registry.
traits->map
added in 2.0.0
(traits->map traits)Takes a traits set/vector and returns a representation suitable for putting into a configuration file.