Bankster.Bic (Bankster v0.4.1)

View Source

Module provides some SWIFT BIC related functions.

See: https://en.wikipedia.org/wiki/ISO_9362

Summary

Functions

Parses a BIC string into its components.

Parses a BIC string into its components.

Turns a Bankster.Bic into a string.

Validates a given string whether it's a valid SWIFT BIC.

Types

t()

@type t() :: %Bankster.Bic{
  bank: binary(),
  branch: binary() | nil,
  country: binary(),
  location: binary()
}

Functions

parse(bic)

@spec parse(term()) :: {:ok, t()} | :error

Parses a BIC string into its components.

Examples

iex> Bankster.Bic.parse("INVALIDBIC") :error

iex> Bankster.Bic.parse("AAAABBCC123") %Bankster.Bic{bank: "AAAA", country: "BB", location: "CC", branch: "123"}

iex> Bankster.Bic.parse("AAAABBCC") %Bankster.Bic{bank: "AAAA", country: "BB", location: "CC", branch: nil}

iex> Bankster.Bic.parse("AAAA BB CC 123") %Bankster.Bic{bank: "AAAA", country: "BB", location: "CC", branch: "123"}

iex> Bankster.Bic.parse("AAAA BB CC") %Bankster.Bic{bank: "AAAA", country: "BB", location: "CC", branch: nil}

iex> Bankster.Bic.parse("AAAA BB CC 123") %Bankster.Bic{bank: "AAAA", country: "BB", location: "CC", branch: "123"}

parse!(bic)

@spec parse!(term()) :: t()

Parses a BIC string into its components.

Will raise ArgumentError if the value can not be parsed.

to_string(bic, opts \\ [])

@spec to_string(t(), [{:format, :pretty | :compact}]) :: binary()

Turns a Bankster.Bic into a string.

Options

  • :format - Specifies the format to use when encoding.
  • :case - Specifies the character case when encoding.

The values for :format can be:

  • :compact - No spaces between components. (default)
  • :pretty - Adds spaces between components

The values for :case can be:

  • :upper - All characters are made to be upper case. (default)
  • :lower - All characters are made to be lower case.
  • :leave - Leaves the characters in the case they are in.

valid?(bic)

@spec valid?(binary()) :: boolean()

Validates a given string whether it's a valid SWIFT BIC.

Note

This ignores whitespace between the components.

Examples

iex> Bankster.Bic.valid?("INVALIDBIC") false

iex> Bankster.Bic.valid?("AAAABBCC123") true

iex> Bankster.Bic.valid?("AAAABBCC") true

iex> Bankster.Bic.valid?("AAAA BB CC 123") true