@@ -35,22 +35,17 @@ defmodule Money do
3535 """
3636
3737 import Kernel , except: [ round: 1 , abs: 1 ]
38+
3839 require Cldr.Macros
40+
3941 alias Cldr.Config
42+ alias Cldr.Currency
4043
4144 @ typedoc """
4245 Money is composed of an atom representation of an ISO4217 currency code and
4346 a `Decimal` representation of an amount.
4447 """
45- @ type t :: % Money { currency: currency_code ( ) , amount: Decimal . t ( ) , format_options: Keyword . t ( ) }
46-
47- @ typedoc """
48- A currency code is an ISO 4217 code expressed
49- as an atom or binary or an ISO 24165 Digital
50- Token ID or Digital Token short name.
51-
52- """
53- @ type currency_code :: atom ( ) | String . t ( )
48+ @ type t :: % Money { currency: Currency . currency_reference ( ) , amount: Decimal . t ( ) , format_options: Keyword . t ( ) }
5449
5550 @ typedoc """
5651 An amount can be expressed as a float, an integer,
@@ -100,7 +95,6 @@ defmodule Money do
10095 # as bankers rounding
10196 @ default_rounding_mode :half_even
10297
103- alias Money.Currency
10498 alias Money.ExchangeRates
10599
106100 defdelegate known_currencies , to: Cldr
@@ -190,7 +184,7 @@ defmodule Money do
190184 "use Money.from_float/2"}}
191185
192186 """
193- @ spec new ( amount | currency_code , amount | currency_code , Keyword . t ( ) ) ::
187+ @ spec new ( amount | Currency . currency_reference ( ) , amount | Currency . currency_reference ( ) , Keyword . t ( ) ) ::
194188 Money . t ( ) | { :error , { module ( ) , String . t ( ) } }
195189
196190 def new ( currency_code , amount , options \\ [ ] )
@@ -320,7 +314,7 @@ defmodule Money do
320314 (ex_money) lib/money.ex:177: Money.new!/2
321315
322316 """
323- @ spec new! ( amount | currency_code , amount | currency_code , Keyword . t ( ) ) ::
317+ @ spec new! ( amount | Currency . currency_reference ( ) , amount | Currency . currency_reference ( ) , Keyword . t ( ) ) ::
324318 Money . t ( ) | no_return ( )
325319
326320 def new! ( currency_code , amount , options \\ [ ] )
@@ -389,7 +383,7 @@ defmodule Money do
389383 """
390384 Cldr.Macros . doc_since ( "2.0.0" )
391385 @ max_precision_allowed 15
392- @ spec from_float ( float | currency_code , float | currency_code , Keyword . t ( ) ) ::
386+ @ spec from_float ( float | Currency . currency_reference ( ) , float | Currency . currency_reference ( ) , Keyword . t ( ) ) ::
393387 Money . t ( ) | { :error , { module ( ) , String . t ( ) } }
394388
395389 def from_float ( currency_code , amount , options \\ [ ] )
@@ -445,7 +439,7 @@ defmodule Money do
445439
446440 """
447441 Cldr.Macros . doc_since ( "2.0.0" )
448- @ spec from_float! ( currency_code , float , Keyword . t ( ) ) :: Money . t ( ) | no_return ( )
442+ @ spec from_float! ( Currency . currency_reference ( ) , float , Keyword . t ( ) ) :: Money . t ( ) | no_return ( )
449443
450444 def from_float! ( currency_code , amount , options \\ [ ] ) do
451445 case from_float ( currency_code , amount , options ) do
@@ -2308,7 +2302,7 @@ defmodule Money do
23082302 """
23092303 @ spec to_currency (
23102304 Money . t ( ) ,
2311- currency_code ( ) ,
2305+ Currency . currency_reference ( ) ,
23122306 ExchangeRates . t ( ) | { :ok , ExchangeRates . t ( ) } | { :error , { module ( ) , String . t ( ) } }
23132307 ) :: { :ok , Money . t ( ) } | { :error , { module ( ) , String . t ( ) } }
23142308
@@ -2372,7 +2366,7 @@ defmodule Money do
23722366 """
23732367 @ spec to_currency! (
23742368 Money . t ( ) ,
2375- currency_code ( ) ,
2369+ Currency . currency_reference ( ) ,
23762370 ExchangeRates . t ( ) | { :ok , ExchangeRates . t ( ) } | { :error , { module ( ) , String . t ( ) } }
23772371 ) :: Money . t ( ) | no_return
23782372
@@ -2410,8 +2404,8 @@ defmodule Money do
24102404
24112405 """
24122406 @ spec cross_rate (
2413- Money . t ( ) | currency_code ,
2414- currency_code ,
2407+ Money . t ( ) | Currency . currency_reference ( ) ,
2408+ Currency . currency_reference ( ) ,
24152409 ExchangeRates . t ( ) | { :ok , ExchangeRates . t ( ) }
24162410 ) :: { :ok , Decimal . t ( ) } | { :error , { module ( ) , String . t ( ) } }
24172411
@@ -2462,8 +2456,8 @@ defmodule Money do
24622456
24632457 """
24642458 @ spec cross_rate! (
2465- Money . t ( ) | currency_code ,
2466- currency_code ,
2459+ Money . t ( ) | Currency . currency_reference ( ) ,
2460+ Currency . currency_reference ( ) ,
24672461 ExchangeRates . t ( ) | { :ok , ExchangeRates . t ( ) }
24682462 ) :: Decimal . t ( ) | no_return
24692463
@@ -2639,7 +2633,7 @@ defmodule Money do
26392633 Money.new(:IQD, "20.012")
26402634
26412635 """
2642- @ spec from_integer ( integer , currency_code , Keyword . t ( ) ) ::
2636+ @ spec from_integer ( integer , Currency . currency_reference ( ) , Keyword . t ( ) ) ::
26432637 Money . t ( ) | { :error , { module ( ) , String . t ( ) } }
26442638
26452639 def from_integer ( amount , currency , options \\ [ ] )
@@ -2719,17 +2713,18 @@ defmodule Money do
27192713 {:error, {Cldr.UnknownCurrencyError, "The currency :ZZZ is invalid"}}
27202714
27212715 """
2722- @ spec zero ( currency_code | Money . t ( ) ) :: Money . t ( ) | { :error , { module ( ) , binary ( ) } }
2716+ @ spec zero ( Currency . currency_reference ( ) | Money . t ( ) ) :: Money . t ( ) | { :error , { module ( ) , binary ( ) } }
2717+ @ spec zero ( Currency . currency_reference ( ) | Money . t ( ) , Keyword . t ( ) ) :: Money . t ( ) | { :error , { module ( ) , binary ( ) } }
27232718
2724- def zero ( money_or_currency , options \\ [ ] )
2719+ def zero ( money_or_currency_code , options \\ [ ] )
27252720
2726- def zero ( % Money { currency: currency } , options ) do
2727- zero ( currency , options )
2721+ def zero ( % Money { currency: currency_code } , options ) do
2722+ zero ( currency_code , options )
27282723 end
27292724
2730- def zero ( currency , options ) do
2731- with { :ok , currency } <- validate_currency ( currency ) do
2732- Money . new ( currency , 0 , options )
2725+ def zero ( currency_code , options ) do
2726+ with { :ok , currency_code } <- validate_currency ( currency_code ) do
2727+ Money . new ( currency_code , 0 , options )
27332728 end
27342729 end
27352730
0 commit comments