Elixir project made for the Stone Tech Challenge and to learn the Elixir language
The idea of the project is to create a set of tools to handle monetary operations, such as transfering money between accounts and currency conversion.
The Money structure is generated by receving values in two ways: as a string representation (e.g.: "15.75"
) or separating its major part (dollar or reais, for example) and minor part (cents/centavos) as integers (e.g.: 15
and 75
). And of course its currency as an atom
(must be compliant with ISO 4217).
After that, this value is internally converted to a Decimal, and all further arithmetic operations are done in Decimal (which uses arbitrary-precision arithmetic), to avoid floating point arithmetic issues.
The IMoney is a module that provides a money abstraction that operates using only integers values. For example, the amount of money 19.90
(a floating point value) is instead represented as an integer 1990
.
Altough the IMoney
module was created as a custom alternative, Money
is the one integrated with FinancialSystem
, since it was implemented on top of the Decimal
package, a module created by a core team member of the Elixir language.
The currency_rates.txt
file contain all the exchange rates (taken from Open Exchange Rates) on 01/31/2018. It is parsed and transformed into a Keyword list, and then used in the conversion. Alternatively, a conversion can be made passing a value and some arbitrary conversion rate.
More details in the documentation.
mix deps.get
to install dependencies
iex -S mix
to start Elixir's interactive shell
mix test
to run unit tests
mix coveralls
to check test coverage
MIX_ENV=test mix coveralls.detail
to show code coverage details
mix format
to format the code ensuring proper style (.formatter.exs
rules)
mix credo
to run credo
mix dialyzer
to run dialyxir static code analysys
Access online documentation here
mix docs
to generate up to date documentation (at doc/index.html
)
Tools used to ensure code quality and proper styling during development:
- The Elixir Formatter (v1.6+) is being used to ensure the code is compliant with the language style guide;
- Credo is a static code analysis tool that is being used to ensure code quality (checking for refactor opportunities, warning about commom mistakes, duplicated code, etc);
- ExCoveralls is a coverage report tool with coveralls.io integration;
- Travis CI is being used for Continuous Integration, executing tests and sending a report to coveralls.io each time a branch is pushed. The
master
branch is protected, which means that only branches that passed all Travis checks will be able to be merged to it; - Dialyzer (Dialyxir) is being used for static code analysis providing warning about problems in the code that are commonly detected by static languages (such as type mismatches) based on the functions
typespec
.