{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Boyle usage\n",
    "\n",
    "## Creating new environment and sample usage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{:ok, []}"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Boyle.list()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "All dependencies up to date\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{:ok, [\"my_new_env\"]}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Boyle.mk(\"my_new_env\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "All dependencies up to date\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       ":ok"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Boyle.activate(\"my_new_env\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Resolving Hex dependencies...\n",
      "Dependency resolution completed:\n",
      "New:\n",
      "\u001b[32m  decimal 1.5.0\u001b[0m\n",
      "\u001b[32m  number 0.5.7\u001b[0m\n",
      "* Getting number (Hex package)\n",
      "* Getting decimal (Hex package)\n",
      "==> decimal\n",
      "Compiling 1 file (.ex)\n",
      "Generated decimal app\n",
      "==> number\n",
      "Compiling 9 files (.ex)\n",
      "Generated number app\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       ":ok"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Boyle.install({:number, \"~> 0.5.7\"})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{:ok, [\"my_new_env\"]}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Boyle.list()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"my_new_env\""
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Boyle.active_env_name()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Number library usage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"$2,034.46\""
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Number.Currency.number_to_currency(2034.46)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"+1 (111) 222-3333\""
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Number.Phone.number_to_phone(1112223333, area_code: true, country_code: 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"100%\""
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Number.Percentage.number_to_percentage(100, precision: 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"1.23 Thousand\""
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Number.Human.number_to_human(1234)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"12,345,678.00\""
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Number.Delimit.number_to_delimited(12345678)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Deactivating virtual environment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       ":ok"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Boyle.deactivate()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "nil"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Boyle.active_env_name()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "ename": "UndefinedFunctionError",
     "evalue": "1",
     "output_type": "error",
     "traceback": [
      "** %UndefinedFunctionError{arity: 1, exports: nil, function: :number_to_currency, module: Number.Currency, reason: nil}"
     ]
    }
   ],
   "source": [
    "# Number library won't work if you deactivate the environment\n",
    "Number.Currency.number_to_currency(2034.46)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Resolving Hex dependencies...\n",
      "Dependency resolution completed:\n",
      "Unchanged:\n",
      "\u001b[32m  decimal 1.5.0\u001b[0m\n",
      "\u001b[32m  number 0.5.7\u001b[0m\n",
      "All dependencies up to date\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       ":ok"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Boyle.activate(\"my_new_env\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"$2,034.46\""
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# and if you activate it will work again\n",
    "Number.Currency.number_to_currency(2034.46)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{%{decimal: {:hex, :decimal, \"1.5.0\", \"b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68\", [:mix], [], \"hexpm\"}, number: {:hex, :number, \"0.5.7\", \"da1ee0434f3c7b84360d33b335d0ee2f86f247f45fbe2e7636e6f55680b464dd\", [:mix], [{:decimal, \"~> 1.2\", [hex: :decimal, repo: \"hexpm\", optional: false]}], \"hexpm\"}}, []}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Boyle.freeze()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{:ok, [\"my_new_env\"]}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Boyle.list()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{:ok, []}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Boyle.rm(\"my_new_env\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Elixir",
   "language": "Elixir",
   "name": "ielixir"
  },
  "language_info": {
   "codemirror_mode": "elixir",
   "file_extension": "ex",
   "mimetype": "text/x-elixir",
   "name": "elixir",
   "nbconvert_exporter": "",
   "pygments_lexer": "elixir",
   "version": "#Version<1.6.5>"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
